1

I have PDF files which get created from a scanner. The PDFs only contain images.

Up to now you can't copy+paste the text if you look at the PDF with Acrobat or an other PDF viewer.

Needed features:

  • OCR: read text from the images
  • Annotate the PDF and create a hidden overlay to make text copy and pastable.
  • Processing of one page should not last longer then 20 seconds
  • Command-line and/or API, no GUI needed

Optional:

  • If there is an API, Python bindings would be nice

I only need to support Linux, no other operating system. Open source preferred, but commercial software recommendations are valid answers, too.

2

The solution you want can be found at our sister site: how to OCR a pdf file and get the text stored within pdf? Quoting this answer:

Best and easyest way out there is to use pypdfocr it doesn't change the pdf. pypdfocr is a python module link here.

pypdfocr your_document.pdf

At the end you will have another your_document_ocr.pdf the way you want it with searchable text. The app doesn't change the quality of the image. Increases the size of the file a bit by adding the overlay text.

I think the command is pretty easy that it doesn't need any GUI. Maybe installing pypdfocr is a bit more verbose:

sudo dnf -y install tesseract 
pip install pypdfocr 

I can't tell about processing time, and certainly you'll need a separate tool to create the annotations – but all your other requirements should be perfectly met:

  • OCR: Yes.
  • open source: Yes.
  • command line, no GUI needed: Yes.
  • Support Linux: Yes.
  • Python bindings: Well, it's plain Python (except for calling to Tesseract).

Alternatively, working the same way, there's another Python module called ocrmypdf. This also uses Tesseract for the OCR process.

A third candidate would be pdfsandwich – but that comes without the Python component.

1

I personally use Adobe's Creative Cloud - All Apps
https://www.adobe.com/creativecloud/plans.html

  • Monthly subscription - cancel anytime.

  • OCR - quality depends on the dots per inch scan. Readability and quality of scanned item.

  • Pasteable text - yes.

  • Editable original text - yes.

  • Notation - Yes

Unfortunately I can not answer for the following:

  • Command Line and or API.

From my research Adobe will work on Linux.

1

Have a look at Tesseract, open source OCR software.

It comes with a command line program and there are Python bindings as well. Packages available in your Linux distro.

apt-get install tesseract-ocr
#convert pdf to scans.tiff
tesseract scans.tiff out pdf
  • ✓ OCR
  • ✓ searchable PDF output
  • ✓ open source
  • ✓ fast enough (v3 faster than v4 though)
  • ✓ command-line and/or API
  • ✓ works on Linux
  • ✓ python bindings
  • Unfortunately tesseract can't take a PDF (containing for example 5 scanned pages) and output a PDF with hidden text annotations. At least I could not find a way to do it. – guettli Jun 6 '18 at 7:58
  • I think the missing step is that you'd need to first convert the PDF file to a multipage TIFF image, which you then pass as input to tesseract. – Edi Jun 6 '18 at 11:14
0

This Python3 based tool does have all features: https://pypi.org/project/ocrmypdf/

  • OCR: yes
  • Annotate the PDF and create a hidden overlay to make text copy and pastable: yes
  • Processing of one page should not last longer then 20 seconds: yes
  • Command-line and/or API, no GUI needed: yes
  • If there is an API, Python bindings would be nice: yes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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