Comments (5)
Comment by jbarlow83
Mon Sep 7 20:14:52 2015
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.
gs -o "$outpdf" -sDEVICE=pdfwrite "$inpdf"
pdftk
also has a feature to fix damaged PDFs.
Can you provide a link to a sample? (Dropbox, etc.)
from ocrmypdf.
Comment by Wikinaut
Mon Sep 7 21:26:44 2015
@jbarlow83
great, because I wanted (but did not) to add some lines from my own project - but did not want to puzzle you with just another information.
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.
from ocrmypdf.
Comment by jbarlow83
Mon Sep 7 22:13:55 2015
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 --pdf-renderer tesseract
), and then uses ghostscript to merge. The error you ran into is in the first step, not later on in the pipeline.
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 --pdf-renderer tesseract
is not the default. I'll be adding code to repair those problems or (more likely) extract the OCR layer from Tesseract's output and graft it into the final PDF, so that I can insert the text layer without transcoding any images.
from ocrmypdf.
Comment by Wikinaut
Mon Sep 7 22:35:32 2015
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):
density = 400
image = yyy.png
file = zzz.pdf
## see http://bertanguven.com/faster-conversions-from-pdf-to-pngjpeg-imagemagick-vs-ghostscript/
gs -dNOPAUSE -sDEVICE=png16m -sOutputFile=$image -r$density -q $file -c quit
from ocrmypdf.
This is a Doublure of #19 .
from ocrmypdf.
Related Issues (20)
- [Bug]: test_semfree fails with ghostscript 10.03.0+
- Pushed docker image is always Ubuntu instead of alpine HOT 1
- [Bug]: HOT 4
- [Bug]: Flood of "Recursion depth exceeded in _find_image_xrefs_page" HOT 5
- [Bug]: multiple spaces not supported for delimitation of bbox parameters HOT 1
- [Bug]: OCR not complete. Parts of all pages are ignored HOT 1
- Error occurred while consuming document out1.pdf: SubprocessOutputError: Ghostscript rasterizing failed. HOT 1
- [Bug]: --tesseract-pagesegmode is not sufficiently documented HOT 1
- Incorrect behavior of text color setting in hocrtransform HOT 2
- [Bug]: crashes with tesseract 5.4.0 HOT 8
- [Bug]: ocrmypdf 16.3.1 fails on a file on Arch that 13.4.0 on Ubuntu handles well HOT 1
- [Feature]: Alternative AI OCR "surya" as opposed to EasyOCR, Just found it today and it dominated the accuracy and speed of Tesseract & EasyOCR HOT 3
- [Bug]: Paperless-ngx Release 2.9.0 Ghostscript rasterizing failed HOT 1
- [Bug]: MetadataProgress does not respect progress_bar=False argument
- [Bug]: No errors and no output for large DPI files HOT 2
- [Bug]: `lots of diacritics - possibly poor OCR` but using standalone tesseract works perfectly HOT 1
- [Bug]: ocrmypdf (16.3.1) and Tesseract 5.4.1 HOT 3
- [Bug]: Existing text is completely replaced with other characters HOT 3
- [Request]: Please make rich logging library an optional dependency HOT 1
- [Feature]: Enable execution on GPU HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ocrmypdf.