Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I have a number of scanned documents in pdf and I want to be able to search them. How can I do that?

Essentially I have to OCR the pdf and then blend the extracted text back into a new pdf. I have unsuccesfully tried a number of different solutions (including the ones found in Adding OCR info to a PDF).

  1. pdfocr (which gives me this issue: https://github.com/gkovacs/pdfocr/issues/7)
  2. pdfsandwich (of which the software center says it is a poor package and I should not install it)
  3. OCRfeeder (in the software center) exports to odt nicely, but does not react when exporting to pdf.
  4. Gscan2pdf exports an all black (but searchable) image as reported in this discussion.
  5. I don't think Pdfxchange viewer can handle doing ocr on the fly on files over 500 pages.

Is there a software package I am unaware of? Or a script that does this?

share|improve this question
I haven't tried it out myself, yet, but I've seen this project get recommended in the past. –  Glutanimate May 29 '14 at 21:22

2 Answers 2

up vote 3 down vote accepted

Following the comment of Glutanimate I have found a working solution. It is the OCRmyPDF script by Fritz.

git clone https://github.com/fritz-hh/OCRmyPDF
sh ./OCRmyPDF.sh -h  # to see the usage

If you get a message saying you should install GNU parallel. It can be done (following http://askubuntu.com/a/298598/115155) with (the second line is optional and depends on your flavor and version):

sudo apt-get install parallel
sudo rm /etc/parallel/config

Finally you can OCR your pdf with the command:

sh ./OCRmyPDF.sh input.pdf output.pdf  # change input and output to the files you want

If it seems the command is unresponsive, you can increase the verbosity using the -v flag (which can be used incrementally as -vv or -vvv). It might be best to test the results first on a shorter pdf. You can shorten a pdf as follows:

pdftk A=input.pdf cat A1-5 output output.pdf
share|improve this answer
Would you accept your answer, to resolve it?(so that it does not come in the unanswered list) –  Registered User Jun 19 '14 at 13:37

pdfsandwich performs exactly this job. I wasn't aware that there is a package provided in the software center, but I'm providing Ubuntu deb packages for it on the project website (see http://www.tobias-elze.de/pdfsandwich/ for details), including the currently most recent version (0.1.2), which is unlikely to be in any software center yet.

If you have a scanned file scanned_file.pdf, simply call

pdfsandwich scanned_file.pdf

which generates the file scanned_file_ocr.pdf with the recognized text added to the scanned pages.

Compared to most existing solutions, it autodetects the tesseract version installed and adapts its behavior accordingly. In addition, it performs preprocessing of the scanned images prior to the OCR process, such as de-skewing or removal of dark edges etc., which can considerably improve optical character recognition.

DISCLAIMER: I'm the developer of pdfsandwich and therefore heavily biased.

share|improve this answer

Your Answer


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.