Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can load the pages I need #67

Open
Thug0416 opened this issue Jul 23, 2018 · 1 comment
Open

can load the pages I need #67

Thug0416 opened this issue Jul 23, 2018 · 1 comment

Comments

@Thug0416
Copy link

pdf.load(0, 2, 3, range(4,8))
gives me this error
TypeError: '>=' not supported between instances of 'range' and 'int'

@chk1
Copy link

chk1 commented Oct 24, 2018

Same error message here.

It occures when you both

  • enable caching and
  • provide a range() for page numbers
  File "C:\Python36-32\lib\site-packages\pdfquery\pdfquery.py", line 625, in _cached_pages
    if target_page >= 0:
TypeError: '>=' not supported between instances of 'range' and 'int'

I'm using Python 3.6 on Windows 7 x64

Minimal example:

import pdfquery
from pdfquery.cache import FileCache

pdf = pdfquery.PDFQuery("HH_2018_Band_2.pdf", parse_tree_cacher=FileCache("cache/"))
pdf.load(range(1,10))

Workaround:

You could provide a large number of numbers via list(range(1,100) but that will result in another Exception because the cache file name is too long and cannot be written to.

To work around that issue, you could change the way the library creates the cache_key

cache_key = "_".join(map(str, _flatten(page_numbers)))

For example, use the md5 hash of all page numbers...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants