-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Fix: page_chars attribute does not exist in some formats of PDF #3796
Conversation
@@ -956,8 +956,12 @@ def __images__(self, fnm, zoomin=3, page_from=0, | |||
enumerate(self.pdf.pages[page_from:page_to])] | |||
self.page_images_x2 = [p.to_image(resolution=72 * zoomin * 2).annotated for i, p in | |||
enumerate(self.pdf.pages[page_from:page_to])] | |||
self.page_chars = [[{**c, 'top': c['top'], 'bottom': c['bottom']} for c in page.dedupe_chars().chars if self._has_color(c)] for page in | |||
self.pdf.pages[page_from:page_to]] | |||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not get it. Why try is in another try?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second try exists to catch and handle exceptions that may occur during parsing of page_chars, so that parsing of the entire PDF does not fail due to parsing problems on individual pages. In the original code, if an exception occurs in page_chars, it is not handled but simply reported as an error and exited.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciation!
What problem does this PR solve?
In #3335 someone suggested to upgrade pdfplumber==0.11.1, but that didn't solve it.
It's actually the special formatting in some of the pdfs that triggers the problem.
Type of change