Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I am looking for an offline scriptable tool that makes an existing PDF file searchable by running OCR on it, replacing the original non-searchable file with the searchable version, and can run unattended.

E.g., www.pdfscannerapp.com - does exactly what I need, but it's GUI only - not scriptable.

I am aware that Evernote makes PDF files searchable, but they remain searchable only when within Evernote.

I am not looking for perfect OCR, even a moderately acceptable OCR is fine, but I would prefer a small utility rather than a bulky software package.

(I am aware of a similar, but different question on AD: Looking for Software to Scan or Convert to Searchable and Signable PDF - however, I don't need to sign or fill PDFs, and my requirement is that the solution is scriptable)

EDIT:

1) Several utilities allow structured text extraction, however in order to be extracted, the text must be there; I am mainly referring to PDFs that are wrapped bitmaps, as is the case with plain PDFs generated by scanners.

2) I am not necessarily looking for a free solution, and I would be more than happy to pay for a good utility that just does what I need, but I am not looking for bulky applications with a million features that include an OCR feature but whose cost does not justify buying them just for the OCR functionality.

3) As stated above, I am not looking for perfect OCR, just a moderately acceptable OCR. Unfortunately, in my experience, tesseract is really below that threshold. I define "moderately acceptable" an OCR that can, say, OCR an utility bill so that at least the account number (customer number) is recognized correctly.

EDIT: "scriptable" or "automatable", that is, able to be triggered automatically and run unattended without human input whatsoever.

share|improve this question
2  
...don't know how hard it would be to do but Tesseract OCR often mentioned code.google.com/p/tesseract-ocr and OCR in Unix.SE. –  hhh Mar 4 '13 at 18:12
1  
There is a similar question here, does the answer fit your requirements? –  patrix Mar 4 '13 at 18:33
1  
You mention OCR. Do your requirements include handling images within PDF, or scanned PDF files? For files that have text within them as simple postscript, then a PDF to text converter like "PDF2Text Pilot" might work for you. –  Tim B Mar 5 '13 at 3:16
    
@patrix I was looking for a smaller utility, not necessarily free but in a different price range. Still, it's a possible solution, thank you. –  magma Mar 5 '13 at 5:02
    
@TimothyButler unfortunately I'm dealing with scanned PDFs (images). But, nice hint, thank you. –  magma Mar 5 '13 at 5:04

8 Answers 8

up vote 2 down vote accepted

It's not entirely clear to me what your requirements are for being able to "script" this from the "command line".

If you are talking about automation, then that is possible with any number of utilities.

ABBYY FineReader Express + Keyboard Maestro + Hazel

I use ABBYY FineReader Express + Keyboard Maestro + Hazel like so:

  1. Hazel monitors a given folder for any new PDFs

  2. if a PDF is found, it is opened in "ABBYY FineReader Express"

  3. Keyboard Maestro then automates the process of turning the PDF into a Searchable PDF (OCR) and saves the file to a different directory.

Now, if you don't own Hazel and Keyboard Maestro already, your initial costs are going to rise pretty quickly (although I depend on both so much I consider them a bargain).

PDFPen + AppleScript + Folder Actions

You could do something similar with PDFPen (or PDFPenPro) and folder actions and AppleScript. See https://gist.github.com/prenagha/1355037 for one example.

Marco Arment did a survey of OCR apps for Mac and found that PDFPen had great results and was easy to automate.

A google search for "PDFpen applescript OCR" will turn up a number of alternatives.

share|improve this answer
    
good answer TJ. Hazel is amazing, I own it and I enjoy using it immensely. I don't currently own abbyy/keyboard maestro, but Hazel + PDFPen is an amazing combo. Overall, while all answers here are generally very good, and serve slightly different audiences, I think that Hazel+PDFPen is a good fit for the original problem. Accepted. –  magma May 10 '13 at 12:10

There is an Apache Software Foundation project called Apache Tika:

A toolkit detects and extracts metadata and structured text content from various documents using existing parser libraries

They support PDF text extraction using PDFBox:

allows creation of new PDF documents, manipulation of existing documents and the ability to extract content from documents. Apache PDFBox also includes several command line utilities

PDFBox makes very simple to extract text from a PDF:

It also has some other nice options that you can see in ExtractText docs.

share|improve this answer
    
Definitely a nice option for extracting text, but there's no OCR capability that I can see. –  magma Mar 11 '13 at 1:59
1  
@magma OCR means "optical character recognition", there is definitely "OCR capability". Now you need to clarify: is your problem to extract text from poor-resolution image such as generated with VGA cam, poor scanner or distant picture? Then your problem is different and requires physical consideration of things such as super-resolution. Please, ask more specific and shorter questions so they can be answered. I suggest you to simplify this question to one feature you want. If you want something more, ask a new question. –  hhh Mar 11 '13 at 4:06
2  
@hhh, one thing is extracting text from a binary file (such as a PDF) so that it is usable and readable, by parsing the binary format. there is nothing optical about it. the text is already there, these utilities just extract it so that it's easy on your eyes, so to speak. optical character recognition is different in that it tries to recognize patterns of pixels in a bitmap and make enough sense of them that it can produce a corresponding text fragment. –  magma Mar 15 '13 at 22:47

I would recommend DEVONThink Pro Office. It is an excellent application and has very good AppleScript support. Alas only the 'Pro Office' version has the OCR capability - so you'll have to shell out £100 ($150).

It would be overkill if you're only using it for scripted OCR - but it's a very good app.

[edit] - ah just re-read your post - it would definitely be overkill!

If you just want OCR from the shell, you could try talking to ABBY whose engine DEVON licences:

http://www.abbyy-developers.com/en:tech:samples:commandline_ocr

share|improve this answer
    
Although the DEVONThink Pro Office in OS X is an overkill, it is interesting. If the developers designed it over OS X and iOS, it may though work (keeping the UI more simple) -- do you know anything like that? Cool idea though -- so the Pro version automatically adds the OCR layer to all kind of things such as screenshots and PDFs? And user can somehow "script" it? –  hhh Mar 5 '13 at 13:31
2  
Yes - the app has a good AppleScript Dictionary, which amongst other things, allows you to convert images stored in the app into searchable PDFs. –  Diggory Mar 5 '13 at 14:01
    
Suppose I take pictures with iPhone or screenshots with OS X and put them to a folder ProjectA, does the DEVONThink add the OCR layer automatically to them even without specifying the language? Suppose you put them to a DropBox and then make DEVONThink in OSX to check the folder automatically, you could work with it over OS X and iOS then? It is a fascinating concept if done well... +1 –  hhh Mar 6 '13 at 2:50
    
In a way, it sounds like EverNote where EverNote adds the OCR but not allowing its exporting like that. Is it possible to export your projects from this software with the OCR? If not, some very simple OCR lib and then some linguistic analysis lib may work the best. Perhaps the other is ABBY, I don't know yet. –  hhh Mar 6 '13 at 2:57
2  
It can recognise in several languages: i.stack.imgur.com/buDLI.png –  Diggory Mar 6 '13 at 8:56

What you want is Tesseract OCR. It's an open source OCR that is maintained by Google and supports a variety of platforms. It also has a native command line interface. It's exactly what you're looking for and available from the Mac ports project as well as homebrew.

Project Home: http://code.google.com/p/tesseract-ocr/

How to install on OS X: http://blog.matt-swain.com/post/26419042500/installing-tesseract-ocr-on-mac-os-x-lion

Usage Example: tesseract -l eng input.pdf output

share|improve this answer

Stackoverflow has related questions under PDF-parsing covering things such as PDFBox and Apache's TIKA that the PDFBox uses. The ruby code below extracts writing from PDF. You need to have good enough resolution for this type of codes to work robustly. So get a good enough scanner with large resolution and then see if some of the softwares work.

Examples

  1. https://github.com/yob/pdf-reader/tree/master/examples

SO threads

  1. http://stackoverflow.com/questions/5217783/pdf-parse-to-text-in-java

  2. http://stackoverflow.com/questions/8149179/alternative-to-tika-pdfbox-for-parsing-pdf-in-solr-any-version-later-than-1-4

  3. http://stackoverflow.com/questions/320621/ruby-pdf-parsing-gem-library

  4. http://stackoverflow.com/questions/15186740/haskell-parsing-reading-content-of-pdf-files

[Edit]

I am not sure whether I understood your problem now. You want to add OCR layer to different kinds of material such as random photos, screenshots, PDFs without OCR layer and so on? I don't know the solution but I am sure someone knows so asked a specific question how to do it with Automator and some OCR software:

Automator-script with an OCR-software to automatically add OCR to material?

share|improve this answer
    
Again: I am not looking to parse or extract text that is already there. I am looking to recognize text (OCR) in PDF file that are essentially images, bitmaps; they do not originally contain any text. –  magma Mar 11 '13 at 2:00
    
@magma please, see my update. You want to automate the addition of OCR layer so you can search over different kinds of documents even without "searchable text"? If you could do this, you could search over all documents in Finder -- you understand? I am surprised if Apple does not do this in coming upgrades... –  hhh Mar 11 '13 at 4:31
    
as stated in my question, yes. –  magma Mar 15 '13 at 22:48

PDFScannerApp does have an unofficial scripting support. Contact the author for the Automator action.

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

4  
To make this answer more useful, can you please add a link to the applications' web site (or into the App Store) and describe your experience with using it? –  patrix May 10 '13 at 6:07
    
@ndf, is that pdfscannerapp.com ? –  magma Dec 6 '13 at 11:39

For this type of self-directed application, I'm a big fan of Hazel.

It makes it extremely easy to script actions without needing to learn a more command line oriented tool like perl or python and paired with the OCR engine of your choice (mine is currently PDF Pen Pro) you should have no problems getting your files processed with minimal fuss.

Both of these are paid software, but the utility of both far extends past this one case. In my situation, with the labor involved in digitizing my past scanned records (and ongoing paper), the price of these far outweighs the time I would have spend programming this elsewhere and now that I own both tools, I can do many other tasks with them.

share|improve this answer

You can make your existing PDF searchable by converting it into text file. You need for that at least Imagemagick, Ghostscript (for PDF conversion) and Tesseract OCR tool.

Some command-line example:

$ wget http://www.fmwconcepts.com/misc_tests/pdf_tests/test.pdf
$ convert -density 300 -depth 8 test.pdf test.png
$ tesseract test*.png test.txt
$ grep -i --color=auto the test*.txt
**The** details as told by surviving crew members, to **the** German publication Spiegel and published on ABC's

This can be extended further to your needs.

To install required tools, on OSX you may install it via Homebrew:

brew install imagemagick jpeg libpng ghostscript tesseract

On Linux use apt-get or yum instead of brew.

For more OCR tools, check: OCR on Linux systems

Related:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.