-
Notifications
You must be signed in to change notification settings - Fork 1.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
Read PDF changed from text to random symbols #654
Comments
The difference is in the Font objects. The new one has a large number of embedded font objects which are all custom encoded. PyPDF2 is not very good at anything other than the standard encodings. The old one has 5 fonts and although some are custom WinAnsi encoding is used in the old one |
is this a Bug or an Limitation? Interestingly although my viewer (where I have patched PyPDF2 to handle a wider range of encoding) does handle the new one it crashes handing the old one which has indirect content streams which then include forms objects. |
It is a limitation which is perceived by the user as a bug :-) Although we might not have the capacity to fix this right now, I would say in general we want to fix this. I see it from the users perspective (hence it's a bug, not a new feature). But that's only terminology^^ |
Fix available see github johns1c/pypdf2The files below show the results of running my amended copy (based on 1.26.0) with running the latest version installed yesterday 2022-04-09. I coded the amendment some time ago and believe it handles custom encoding as well as to_unicode tables. My version of wx.lib.pdfviewer uses this code and seems to handle the vast majority of PDFs. Martin - do you think that my code could be incorporated into the "production" version? 1 I will check that I have the latest code on github
I am willing to do the work but I might need some hand holding. Chris Johnson |
Yes, for sure!
That's what we (me and the PyPDF2 community) are here for :-) Just make a PR, we will walk through it :-) |
I see that you haven't forked from PyPDF2: https://github.com/johns1c/PyPDF2 Could you maybe fork from PyPDF2: https://docs.github.com/en/get-started/quickstart/fork-a-repo then make the changes that fixed the issue + create a PR? |
Will take a few days as am away from home
Chris (from my iThingy
… On 16 Apr 2022, at 12:21, Martin Thoma ***@***.***> wrote:
I see that you haven't forked from PyPDF2: https://github.com/johns1c/PyPDF2
Could you maybe fork from PyPDF2: https://docs.github.com/en/get-started/quickstart/fork-a-repo
then make the changes that fixed the issue + create a PR?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.
|
Dear Martin,
At present my PyPDF2 only contains the Python code that would be installed in site-packages (the PyPDF2 subdirectory of the original). I will need to fork the PyPDF/PyPDF2 code, merge the two versions (mainly incorporating the recent changes to literals) and test.
I have a few questions regarding this
1. Does my fork have to be called PyPDF2?
2. Can I run Github actions without breaking anything (or releasing it)?
3. Are existing regression tests sufficient (my own tests tend to be read-only)
4. Is there a way of installing from a fork (say using test PyPi) that would allow me to test without affecting anyone else.
5. Are you currently making changes which I would need to track particularly widespread changes such as the recent literal change which I am now trying to incorporate.
Chris
Sent from Mail for Windows
From: Martin Thoma
Sent: 16 April 2022 12:21
To: py-pdf/PyPDF2
Cc: C Johnson; Comment
Subject: Re: [py-pdf/PyPDF2] Read PDF changed from text to random symbols(Issue #654)
I see that you haven't forked from PyPDF2: https://github.com/johns1c/PyPDF2
Could you maybe fork from PyPDF2: https://docs.github.com/en/get-started/quickstart/fork-a-repo
then make the changes that fixed the issue + create a PR?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Good morning!
|
This issue has been fixed with #924 Examplefrom PyPDF2 import PdfReader
reader = PdfReader("magnetic.pdf") # https://onlinelibrary.wiley.com/doi/10.1002/mrm.29078
text = reader.pages[0].extract_text() text then is:
|
Thanks a lot everyone! Really appreciate the work you put into this fix/feature, and overall package! |
by now #924 is not relased. I will relase |
The highlight of the 2.1.0 release is the most massive improvement to the text extraction capabilities of PyPDF2 since 2016 🥳🎊 A very big thank you goes to [pubpub-zz](https://github.com/pubpub-zz) who took a lot of time and knowledge about the PDF format to finally get those improvements into PyPDF2. Thank you 🤗💚 In case the new function causes any issues, you can use `_extract_text_old` for the old functionality. Please also open a bug ticket in that case. There were several people who have attempted to bring similar improvements to PyPDF2. All of those were valuable. The main reason why they didn't get merged is the big amount of open PRs / issues. pubpub-zz was the most comprehensive PR which also incorporated the latest changes of PyPDF2 2.0.0. Thank you to [VictorCarlquist](https://github.com/VictorCarlquist) for #858 and [asabramo](https://github.com/asabramo) for #464 🤗 New Features (ENH): - Massive text extraction improvement (#924). Closed many open issues: - Exceptions / missing spaces in extract_text() method (#17) 🕺 - Whitespace issues in extract_text() (#42) 💃 - pypdf2 reads the hifenated words in a new line (#246) - PyPDF2 failing to read unicode character (#37) - Unable to read bullets (#230) - ExtractText yields nothing for apparently good PDF (#168) 🎉 - Encoding issue in extract_text() (#235) - extractText() doesn't work on Chinese PDF (#252) - encoding error (#260) - Trouble with apostophes in names in text "O'Doul" (#384) - extract_text works for some PDF files, but not the others (#437) - Euro sign not being recognized by extractText (#443) - Failed extracting text from French texts (#524) - extract_text doesn't extract ligatures correctly (#598) - reading spanish text - mark convert issue (#635) - Read PDF changed from text to random symbols (#654) - .extractText() reads / as 1. (#789) - Update glyphlist (#947) - inspired by #464 - Allow adding PageRange objects (#948) Bug Fixes (BUG): - Delete .python-version file (#944) - Compare StreamObject.decoded_self with None (#931) Robustness (ROB): - Fix some conversion errors on non conform PDF (#932) Documentation (DOC): - Elaborate on PDF text extraction difficulties (#939) - Add logo (#942) - rotate vs Transformation().rotate (#937) - Example how to use PyPDF2 with AWS S3 (#938) - How to deprecate (#930) - Fix typos on robustness page (#935) - Remove scripts (pdfcat) from docs (#934) Developer Experience (DEV): - Ignore .python-version file - Mark deprecated code with no-cover (#943) - Automatically create Github releases from tags (#870) Testing (TST): - Text extraction for non-latin alphabets (#954) - Ignore PdfReadWarning in benchmark (#949) - writer.remove_text (#946) - Add test for Tree and _security (#945) Code Style (STY): - black, isort, Flake8, splitting buildCharMap (#950) Full Changelog: 2.0.0...2.1.0
Hi there,
I've been using this script regularly on PDF for work,
and for all PDFs I used before a few months ago, the page text was correctly being read as text (e.g. the PDF downloadable here: https://onlinelibrary.wiley.com/doi/10.1002/mrm.28965).
However, now recent PDFs (like this one: https://onlinelibrary.wiley.com/doi/10.1002/mrm.29078) are reading the pages as random symbols, like this (generated by adding
print(page_text)
):So clearly, my keyword detection isn't working anymore.
I can't seem to find a difference in the PDF files (they are both Adobe InDesign 15.1 (Windows), Adobe PDF Library 15.0; modified using iText 4.2.0 by 1T3XT). Any clue on how to resolve this for the newer PDFs I'm using?
The text was updated successfully, but these errors were encountered: