-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Some input PDFs with Tesseract-OCR throw error in PyPDF2.utils.PdfReadError(Unexpected escaped string: b'{')' raised in ... #1
Comments
Comment by jbarlow83 There's an error in the PDF file. I run qpdf to try to fix errors before anything else, but it can't fix everything. You could "re-fry" the PDF with ghostscript, which rewrites and hopefully fixes the error. This has other side effects.
Can you provide a link to a sample? (Dropbox, etc.) |
Comment by Wikinaut @jbarlow83 Give me some time, I will try to find what went wrong (the scanned PDF was produced with gscan2pdf and tesseract. Perhaps I used already pdftk to merge some parts, and this step introduced the problem). My own project (not published yet) creates single pages from a multi-page input pdf, converts them to single lossless-compressed images (png, not using convert but ghostscript), tesseract-ocrs (pdf rendering mode) page-by-page, and then uses pdftk to concatenate (re-merge) the single pages to the multi-page, double-layer output pdf. In that way, pdf errors are almost never coming up. |
Comment by jbarlow83 I'd like the PDF because any errors get added to the test suite. I'm less interested in what produced the problem so much as trying to make sure all readable PDFs are accepted even if they are invalid. Your project is quite similar to what this one does right now - just so you're aware. ocrmypdf converts pages to PNG uses ghostscript (btw: ImageMagick's convert also uses ghostscript, it just uses it badly), then uses tesseract for PDF rendering (optional with Tesseract's PDF rendering has some issues (at least as of 3.03). It gets DPI wrong, it produces PDFs with syntax errors, and it can inflate file size in some situations. For those reasons |
Comment by Wikinaut re. ghostscript vs. convert, yes, you are fully right. See http://bertanguven.com/faster-conversions-from-pdf-to-pngjpeg-imagemagick-vs-ghostscript/ . And thanks for all the other infos. BTW, I helped the tesseract people to fix a problem with the re-compression of the image (and I am proud, because it was difficult for some days). For a certain period, they lossy-re-compressed the input image (because the design goal was then to create minimal file sizes, which is a wrong goal), which introduced coding artefacts. This is fixed since about one year, and current tesseract version are coding very well. When you now say, that Tesseract introduces PDF syntax errors, this explains my current issue. Thanks for info. Please, if you have further information why or when Tesseracts creates wrong PDFs, pls. report your observations upstream. They (user zdenop) will fix the issue. Just for your information: From my script the line where a pdf page is losslessy converted to an image (which is then input to tesseract, and rendered to pdf):
|
Squashed commit of the following: commit 974de2e8ccad7fd34694f2c3a7a17c64bb52cdab Merge: a8d7f96 ee04aa7 Author: James R. Barlow <james@purplerock.ca> Date: Sat Dec 4 20:22:50 2021 -0800 Merge branch 'update_bash-completion' of git://github.com/FPille/OCRmyPDF into FPille-update_bash-completion commit ee04aa7 Author: FPille <f.pille@gmail.com> Date: Thu Oct 14 11:09:23 2021 +0200 update commit 76f6453 Author: FPille <f.pille@gmail.com> Date: Thu Oct 14 11:04:10 2021 +0200 updated and descriptions for arguments and choices added deprecated arguments removed bug fix: typo "_init_completion" instead of "_init_completions" commit de9b93e Merge: c23374d 42713b7 Author: Frank <50119297+FPille@users.noreply.github.com> Date: Thu Oct 14 08:08:11 2021 +0200 Merge branch 'jbarlow83:master' into master commit c23374d Merge: 40b2ebc c409fa5 Author: Frank <50119297+FPille@users.noreply.github.com> Date: Wed May 26 20:31:00 2021 +0200 Merge branch 'jbarlow83:master' into master commit 40b2ebc Merge: 79c84ee 7e388f5 Author: Frank <50119297+FPille@users.noreply.github.com> Date: Sat Jun 1 11:09:07 2019 +0200 Merge pull request #1 from jbarlow83/master update master
Squashed commit of the following: commit 974de2e8ccad7fd34694f2c3a7a17c64bb52cdab Merge: a8d7f96 ee04aa7 Author: James R. Barlow <james@purplerock.ca> Date: Sat Dec 4 20:22:50 2021 -0800 Merge branch 'update_bash-completion' of git://github.com/FPille/OCRmyPDF into FPille-update_bash-completion commit ee04aa7 Author: FPille <f.pille@gmail.com> Date: Thu Oct 14 11:09:23 2021 +0200 update commit 76f6453 Author: FPille <f.pille@gmail.com> Date: Thu Oct 14 11:04:10 2021 +0200 updated and descriptions for arguments and choices added deprecated arguments removed bug fix: typo "_init_completion" instead of "_init_completions" commit de9b93e Merge: c23374d 42713b7 Author: Frank <50119297+FPille@users.noreply.github.com> Date: Thu Oct 14 08:08:11 2021 +0200 Merge branch 'jbarlow83:master' into master commit c23374d Merge: 40b2ebc c409fa5 Author: Frank <50119297+FPille@users.noreply.github.com> Date: Wed May 26 20:31:00 2021 +0200 Merge branch 'jbarlow83:master' into master commit 40b2ebc Merge: 79c84ee 7e388f5 Author: Frank <50119297+FPille@users.noreply.github.com> Date: Sat Jun 1 11:09:07 2019 +0200 Merge pull request #1 from jbarlow83/master update master
Issue by Wikinaut
Mon Sep 7 18:56:47 2015
Originally opened as fritz-hh/OCRmyPDF#120
A few PDF input files (which were already processed by tesseract-ocr pdf mode) throw an error in OCRmyPDF even in the
--force-ocr
mode. At the moment, I have no idea what exactly happens, but the problem appears to be in PyPDF2 (I use PyPDF2 1.25.1).The error message is only shown when OCRmyPDF is used with the
-v
option.Do you have an idea what went wrong in these cases, or what else can be done to let OCRmyPDF apply another OCR run to such a PDF?
Full output:
The text was updated successfully, but these errors were encountered: