5 ms·
OCRmyPDF: Add an OCR text layer to scanned PDF file
- solardev 4y agoFYI Google already does this automatically: https://searchengineland.com/google-using-ocr-to-index-scanned-documents-15318 https://searchengineland.com/google-using-ocr-to-index-scann...
- layer8 4y agoThis is standard functionality of every scan-to-PDF application nowadays. But I guess it’s nice if you happen to come across a scan-only PDF.
- gsich 4y agoSome viewers can do that on the fly, I have used this with Adobe Acrobat.
- danso 4y agoYeah this would’ve been much more exciting for me had I discovered it 5 years ago (its git log starts in 2013). But having a CLI command that I can script will be nice for the occasional project of random scanned papers, or personal documents that I don’t necessarily want in the cloud even if the OCR is free
- gwern 4y agoI think you're underselling ocrmypdf, which I use heavily: 1. Scan-only PDFs are shockingly common: I download papers all the time which are scan-only. 2. Non-scan-only PDFs often have garbage OCR. I assume this is because they were done long ago and never redone since. (Tesseract has gotten a lot better over the years.) Not terribly rarely, I use ocrmypdf to forcibly redo OCR layers because they are unusable. 3. ocrmypdf supports JBIG2, and possibly for other reasons as well, generates smaller PDFs; this is true even for 'native' PDFs or ones with good OCR. I routinely see PDFs I download, hot off the presses just days before with presumably their latest and greatest publishing stack from major scientific publishers, which shrink by a third or a half or sometimes wind up as much as 10x smaller. Not being a PDF expert, I have no idea how they manage to waste so much space, but they manage it. I also found that standard scan tools I was using like imagescan or gscan2pdf or 1dollarscan were not producing as small PDFs as ocrmypdf did. 4. ocrmypdf will also write PDF/A by default. It's true that most PDFs you download or create will probably be perfectly readable 50 years from now with no special effort... But it's nice to have that extra bit of archival compliance.
- gumboshoes 4y agoI agree on all points. I use the following one-liner in directories of PDFs to reduce their file size while retaining dimensions, not hurting readability, and keeping the embedded OCR text in place. It skips re-running the OCR. It's basically a recipe from the docs, I believe. find . -name '*.pdf' | parallel --tag -j 1 ocrmypdf --tesseract-timeout=0 --skip-text --jbig2-lossy --optimize 3 --output-type pdf '{}' '{}-sm.pdf'
- dataflow 4y agoFun fact: even Gmail OCRs image files. If you search for emails using keywords, it'll use the OCR results. I just wish there was a way to get access to the OCRed text.
- hackernewds 4y agoGoogle can do this at scale. Google Lens is amazing, and the swipe up+select on Pixel (stock Android) is amazing. yet with all things Google, so poorly advertised
- tyingq 4y agoNot exactly what you're asking for, but Google Keep has a "grab image text" menu item for any note that has an image in it. I assume it's using the same backend.
- pronoiac 4y agoI think I looked at using Google Drive for OCR, but it was limited to 2 meg files or only a few pages or something? I had a lot of higher resolution pages (1k pages, 300 or 600dpi), so this was a non-starter for me.
- gumboshoes 4y agoAs mentioned in the other replies, Google's automatic OCR is limited. OCRmyPDF is designed for PDFs. So if you download a 1000+ page public-domain dictionary off of Archive.org (which is something I do regularly), and you want to re-run the OCR because Internet Archive doesn't tune its OCR very well for multilingual works (if it all), then OCRmyPDF is going to beat Google's automatic OCR every time. However, I recently paid a programmer to fork OCRmyPDF to give it the option to use Google's OCR engine instead of Tesseract. That fork is here: https://github.com/ualiawan/OCRmyPDF https://github.com/ualiawan/OCRmyPDF. It's more fiddly than the regular OCRmyPDF, and it requires a Google Cloud Vision account (which charges some fraction of a cent for each page OCRed), but it works well, and in some cases may produce better results than OCRmyPDF, although you must be sure to specify the language of the document.
- bkanuka 4y agoVery cool - I'm interested in your(?) fork of OCRmyPDF. But can I ask..Why a fork and not a plugin to OCRmyPDF? which supports adding new OCR backends.
- deleted 4y ago[deleted]
- anotherhue 4y agoI used this project recently and it is fabulous.
- lelandfe 4y agoI use OCRmyPDF to scan comic book PDFs en masse so they’re searchable, which makes keeping up with tons of characters more doable It’s a really nice piece of software!
- BaraBatman 4y agoLove this. How do you do it? Any code online to take a look?
- lelandfe 4y agoTheir docs are actually pretty good! https://ocrmypdf.readthedocs.io/en/latest/batch.html https://ocrmypdf.readthedocs.io/en/latest/batch.html After that, it’s a simple matter of doing Cmd-F in macOS - Finder searches over PDF text :)
- amelius 4y agoWhat is a good OCR package that is open source? Perhaps I'm using it in the wrong way, but my experience with Tesseract is not so great.
- is_true 4y agoEasy OCR
- yoquan 4y agoDocTR: https://github.com/mindee/doctr https://github.com/mindee/doctr It also has TensorFlow.js version to run in-browser: https://blog.tensorflow.org/2022/06/ocr-in-browser-using-tensorflowjs.html https://blog.tensorflow.org/2022/06/ocr-in-browser-using-ten...
- no-reply 4y agoDemo: https://demo-doctr-tensorflowjs.mindee.com/ https://demo-doctr-tensorflowjs.mindee.com/
- amelius 4y agoThanks, I tried it but it has the same problem as: https://news.ycombinator.com/item?id=32033480 https://news.ycombinator.com/item?id=32033480 and is actually a bit worse.
- jwilk 4y agoDoes it actually work? I haven't managed to make it produce anything but empty pages. Also, I didn't appreciate that it downloaded models behind my back.
- lobochrome 4y agoIMHO tesseract is still the gold standard os. Important to specify language. To bad google abandoned it kind of. Abbyy finereader is still the best ocr out there. Alas not open. (And Russian)
- pronoiac 4y agoI recently used this! Some other useful features: * adjusting metadata, like author and title * recompressing the scans with lossless JBIG2, which led to a smaller pdf by 20% or so
- ramraj07 4y agoDropbox premium does this. My entire historical archive is up there and am super happy with their search!
- pronoiac 4y agoDo they edit the pdfs, or do they index them so you can search? OCRmyPDF does the first, so it's usable elsewhere; glancing around, it looks like Dropbox does the second, which can't be saved for use elsewhere.
- ramraj07 4y agoAgreed, it’s not perfect. I might still run ocrmypdf on all my pdfs at some point.
- codetrotter 4y agoGitHub repo https://github.com/ocrmypdf/OCRmyPDF https://github.com/ocrmypdf/OCRmyPDF
- FooBarWidget 4y agoWhat a useful tool! Right now I scan my documents using VueScan, which can add an OCR layer to PDFs automatically, but that only works if I have a physical document — I am out of luck if I want to add OCR to an existing PDF. This tool looks like it can help. I have some notary documents from when I bought a house. Searching through it manually is a hell, not only because notaries use obscure language and the document is huge, but also because they format the document in a way that's safe against edits. I have longed for a way to Ctrl-F it.
- camhart 4y agohttps://www.naps2.com/ https://www.naps2.com/ is a great pdf scanner that supports ocr as well.
- 7839284023 4y agoI loved NAPS2 on Windows! Sadly on Linux I could never got it working reliably and had to switch over to VueScan... But I'll always miss NAPS2.
- sohel1010 4y agoyaah
- ducktective 4y agoNice utility! It uses Tesseract internally. Has anyone done a comparison on Tesseract 4 vs 5 vs PaddlePaddle?
- encryptluks2 4y agoI hate to say it but Adobe Acrobat has probably one of the best scanning tools with OCR that I've seen.
- phren0logy 4y agoReally!? I have found Acrobat to be pretty awful but I work with complex documents (lots of columns, weird forms, etc). I have found ABBYY to the gold standard. Thankfully, that's also the engine built into a number of other bits of software, including DevonThink and some PDF readers.
- airbreather 4y agoI think Abbyy kills it, they really are Enterprise grade, unlike Adobe who like to claim they are but crash more often than Taki Inoue ever did. For standard grade I find masterpdf kills Adobe almost all around, including OCR and search/index, and it lets you edit pdf elements more easily than editing a word document. Not FOSS, but I found it well worth my$50 or whatever it was, esp compared to Adobe and Foxit. Crashes way, way less than Adobe as well, can also get a linux version, which you can't with Adobe. I have a full Adobe DC license supplied by work, but the only time I use Adobe by choice is if I want the outrageously useful and uniquely packaged functionality provided by the Autobookmark (Evermap) or Debenue plugins, but tbh they only really do things that Adobe should have baked in anyway if they weren't trying to gouge you on basic functionality they lock up (eg create bookmarks based on a font, page position and a regex, and then make TOC from bookmarks - lets you create a TOC for a pdf that has none and you don't have the native, for instance). I've been doing a deep dive in to pdf format for some time now.
- encryptluks2 4y agoI'll check it out. I haven't tried Abbyy yet but have tried a few others, and none of them unfortunately came close to the capabilities of Adobe Acrobat. I don't like Adobe Acrobat because I primarily use Linux, but do keep a Windows VM or partition around to scan documents.
- lhoff 4y agoI use it together with my Nextcloud. There is a workflow integration so that it all works automatically for uploads in specific folder (for me). Example: I have a folder for invoices where I upload scans of important ones and all if them get automatically OCRed. https://apps.nextcloud.com/apps/workflow_ocr https://apps.nextcloud.com/apps/workflow_ocr
- zihotki 4y agoIn case if anybody is looking for a reliable and free swiss army knife tool for PDFs, I'd like to recommend https://www.pdf24.org/en/ https://www.pdf24.org/en/ - it supports splitting, converting, signing, OCR, and many other operations. Both online and offline tools are available. Not an opensource product though and offline version is Windows only.
- dwheeler 4y agoA related option: LibreOffice has a cool option where you can generate the PDF with the editable text format embedded. You get a clean PDF that is also fully editable. Easy tech, but also useful.
- jcuenod 4y agoI use OCRmyPDF on a regular basis to OCR journal articles my library sends me. I've found it works great on English but (with appropriate language packs installed) works poorly on Greek and Hebrew. It also makes no effort to understand the layout of pages (e.g., tables). The project is fantastic, though. I've often considered building a web frontend that cleans up PDFs and then OCRs them using OCRmyPDF. For cleaning, check out https://scantailor.org/ https://scantailor.org/
- gumboshoes 4y agoI use OCRMYPDF nearly every day. It already has cleaning functions: deskewing, page rotation, despeckling, contrast, etc. The docs linked above show all the many useful options in full.
- rbanffy 4y agoA quick note that many government agencies in many countries like to avoid complying with the spirit of transparency laws by posting scan-only PDF files. Batch OCR is an incredibly valuable tool for activists.
- airbreather 4y agoAs usual with Tesseract it's great if you want generic OCR that gives 97-98% accuracy with little to no work, but it's never going to hit 100% or near across all fonts, diagrammatic input etc. I have just given up on Tesseract for parsing engineering diagrams where the one single font is used throughout and rolled my own non-ML OCR using opencv that requires a little setup but easy hits 99.9% on a character basis and is way quicker, plus uses way less data stored. I couldn't get Tesseract to pick Z against 2, I against 1 etc reliably when no serifs, no matter what i did for preprocessing - dilate/erode, threshold, border, contours with smoothing, x2 and x5 resize, all the modes and so on. Because it's engineering diagrams only limited contextual guidance can be used, it's basically independent characters each time. They say retraining Tesseract won't help, but surely it would for certain fonts - what am I supposed to do about the 1 vs I then, as one example? I could pre or post process, but once I set up to do that for a few specific cases I can do a little more and then do the whole alphabet and get way better performance without Tesseract at all. And then there is the stupid Autocad font designed for pen plotters like HP-7585 or HP-7475 that no one owns any more, but the font with the square zero lives on, and that is a problem on it's own. Anyhoo, I tried out the OCRmyPDF on a few things, it could be useful in the right circumstances, but by no means magic. Nanonets or pdfsumo seem to do way better, plus can handle tables.
- gumboshoes 4y agoI think a lot of the comments are missing the PDF in the name OCRmyPDF. Having a software package that combines several open source tools to disassemble a PDF, do cleanup on each page, run OCR on them, and then reassemble them into a new PDF with the text embedded is why OCRmyPDF is so great. I see lot of worthy software also being mentioned in the discussion but a lot of it requires rolling your own cleanup steps or our reassembling steps because the packages are designed for single-image scans or only deliver JSON output (which requires some fairy dust to get back properly into HOCR and then into a PDF). As I posted above, I got someone to add Google Cloud Vision as an alternate OCR engine for OCRmyPDF — I'd love to see more OCR engines (like ones suggested here) made possible.
- hcs 4y agoIs there a recommended way to manually review and correct OCR generated like this? I've tried different methods over the years but nothing makes it easy enough, and tools that deal with hOCR all seem to be broken in different ways.