-
Notifications
You must be signed in to change notification settings - Fork 29
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
Improve OCR layer compatibility with MacOS Preview via hocr renderer #35
Comments
I tried to replicate this problem on Linux with You said that switching from I don't have many ideas here, except to note the problem appears to be with macOS Preview. |
Thank you very much for trying to replicate the problem. On both a Big Sur and a Mojave machine, after Preview on either machine removes a page, saves, closes and then re-opens the now-shorter PDF, the text is no longer searchable and if copied to the clipboard and pasted, it's all the same question-mark-in-a-box glyph. Also, the file actually grows slightly when a page is removed. This happens when either Without being certain, the most likely explanation so far is that Preview breaks the PDF when it removes a page, but won't do this to a PDF created by the Fujitsu software's generated PDFs. |
Maybe the Fujitsu software outputs a different character encoding? Can you upload a small sample scanned and OCRed with the Fujitsu software? |
Any updates on this @watou ? |
No further information provided from user, closing. Feel free to re-open if you have additional info to provide. |
Just reporting that the following changed pieces yield the same unwanted result (if one removes one or more pages using macOS Preview from a multi-page PDF created by this script that includes text added by tesseract), re-opening the PDF in any viewer changes all text into the same "nonsense" glyph).
I'm amazed this result isn't reproduced by others! |
@watou Thanks for the update. The information doesn't help me unfortunately. What I would need from you ideally is an upload of a PDF scanned and OCRed via this project, and one scanned and and OCRed via the Fujitsu software. I would like to compare the two to see if there are any notable differences in the OCRed content. I'd also like to try opening both PDFs on a Mac machine I have access to. |
I will send you those shortly; thanks for having a look when you have them! |
Hi @rocketraman, the file SaneScanPdf.pdf was scanned with a Fujitsu ScanSnap S1500M using your script, and the command line
The file ScanSnapManager.pdf was scanned with ScanSnap Manager Version 6.3 L70 on macOS Mojave 10.14.6. If you edit the first file with macOS Preview (multiple versions) and remove the second page, save, exit, re-open, the text you can select and copy to the clipboard has become illegible. This does not happen when editing the second file. This problem occurs with a variety of paper document tests, not just this two-page example. Thank you for your efforts in identifying this issue. It's a genuine nuisance because the duplex scanning often fails to remove the blank reverse of many pages, and when I use Preview to remove them, the OCR is fatally garbled as a result. |
I've replicated the issue with your (non-manager) scan, as well as another I did locally. I'll continue to do a bit of research to see if there is something simple to change to improve compat with MacOS Preview, however, I note this appears to not be the first time (by a long shot) that people have noted this buggy behavior with MacOS Preview, which links to 4 or 5 various posts about this issue: https://annoying.technology/posts/86f4ea27e4cd90d0/ and a related HackerNews thread: https://news.ycombinator.com/item?id=25447830 Therefore, its unlikely I'll spend much effort on this, as it is definitely Apple's problem. |
Thanks for looking. From your first link provided it sounds like Apple did some vendor-specific hacks to keep Preview from breaking ABBYY FineReader-produced OCR; if so, that's very fragile territory to try to improve. But just for completeness, the "garbage" I see always looks like the image below, not the garbled text in the image at your first link. Thanks again! |
I also replicated the issue by not using OCR in sane-scan-pdf, and instead adding the OCR layer post-scanning via OCRmyPDF. Same issue when adding OCR via that tool using the default PDF render mode which is "sandwich". However, when using the older "hocr" PDF render mode, editing the PDF in Preview worked fine. However, the "hocr" mode requires combining the hocr XHTML output from Tesseract with the scanned PDF, and I'd need to do a bit more research to understand how ocrmypdf does that. It may be possible to replicate that behavior in sane-scan-pdf. Its unlikely I'll have the time to do this myself in the near future, but hopefully that helps someone else that may want to take a crack at this! |
Probably the easiest option is to just use ocrmypdf as an alternative to directly using tesseract. We could use this if, for example |
@rocketraman If the pipeline had the OCR option you've described, that would be a perfect solution, especially since ocrmypdf seems like a mature and well packaged (optional) dependency. |
@watou On the other hand, I'm not sure that using ocrmypdf directly in the scanner script adds much value. You could very easily just not use |
I like the option of having your script produce the "default" handling of scanned documents, which in my case includes embedded OCR. Since your script already does this but in the limited range of choices that don't overcome the Preview problem, adding in a known workaround by optionally supporting a choice that does keeps your solution to one step per document. Of course I could modify your or my script and do an in-place ocrmypdf directly there, but it's nice if everything is kept to options you offer. I'm happy to fix it in my own scanbd script, but then it's something for the next poor Apple user to bump up against. But whichever path makes more sense to you is great! |
I do duplex scans only with my Fujitsu ScanSnap S1500M and edit the resulting searchable PDF files in macOS Preview to remove any pages I don't want. However, the PDF files combined by
pdfunite
, once edited, make the embedded OCR'd text into strings of question-mark-in-box characters. This stops the files from being searchable.When I change the
scan
script thus it does NOT solve this problem, and tried a number of permutations ofgs
parameters for PDF output.Verified that this problem occurs on a different computer running a different macOS version.
The commercial ScanSnap software and included OCR produces PDF files that can be edited and the OCR'd text remains usable.
The text was updated successfully, but these errors were encountered: