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

Fix: page_chars attribute does not exist in some formats of PDF #3796

Merged
merged 9 commits into from
Dec 3, 2024

Conversation

cyhasuka
Copy link
Contributor

@cyhasuka cyhasuka commented Dec 2, 2024

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

  • Bug Fix (non-breaking change which fixes an issue)

@@ -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:
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciation!

@KevinHuSh KevinHuSh merged commit 7b6a5ff into infiniflow:main Dec 3, 2024
2 checks passed
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

Successfully merging this pull request may close these issues.

2 participants