3

Some companies provide software for Windows with their scanners* that can create PDFs from scanned pages which look exactly like the scanned material (as if it were just full-page images) but the text is recognized and copyable.

How can I create PDFs like this on Ubuntu?

Note that I don't want to convert scanned text into regular text. I would like to keep the resulting PDF looking picture-perfect as the original pages but add a recognized text layer over it for ease of use.

I have a working high-resolution scanner which I use with XSane currently. It scans the pages fine and creates beautiful, high-DPI images.

* namely, Canon with LiDE 220

  • 1
    You might want to Google "PDF sandwich" for better results. Anyways, currently the best solution for accuracy in text positioning is using PDF Xchange Viewer under Wine. – Andrea Lazzarotto Sep 24 '17 at 11:27
  • A "PDF sandwitch" is exactly what I want to create! Thank you for this term. – Damn Terminal Sep 24 '17 at 11:30
  • 1
    have a look here, towards the bottom is pdfocr help.ubuntu.com/community/OCR – ravery Sep 24 '17 at 11:34
  • @AndreaLazzarotto "Use pdfsandwich" is exactly the answer I was looking for. Post it and I'll accept. Maybe mention that it's in the repo and additional language packs are available as tesseract-ocr-[three letter language code]. – Damn Terminal Sep 24 '17 at 12:02
  • 1
    @DamnTerminal pdfsandwich (the command) gives a terrible output unless it changed very recently. I would be a bit ashamed to post that as an answer. :P – Andrea Lazzarotto Sep 24 '17 at 14:47
3

Preamble

You are looking for a PDF sandwich, i.e. a scanned PDF with an invisible layer of text (or a layer of text which is simply placed behind the picture of each page).

There are several ways to create one. I will use the paper Term Weighting Approaches in Automatic Text Retrieval as an example of a document that needs OCR.

The pdfsandwich command

First of all, install this tool from the repositories:

sudo apt install pdfsandwich

Then you can just run it on your PDF file and wait:

pdfsandwich document.pdf

Screenshot of Evince showing a PDF sandwich

In the past, this method was not very precise, especially w.r.t. text positioning. It seems that now things got a lot better. Example from the PDF:

Abstract–The experimental evidence accumulated over the past 20 years indicates that

If you highlight the text in Evince, black boxes are shown.

PDF-XChange Viewer

This is a freeware, Windows-only program that works perfectly under Wine if you use the 32-bit version in a 32-bit Wine prefix. For this, I suggest using PlayOnLinux because it's very easy to select the latest Wine version and the fact that you want a 32-bit prefix.

Once installed, you can run it and select the OCR icon on the toolbar:

Screenshot of PDF-XChange Viewer under Wine

The output is usually very good and the text placement is precise. Example from the PDF:

Abstract--The experimental evidence accumulated over the past 20 years indicates that

If you highlight the text in Evince, the text is shown in a sans-serif font.

OCR.space

This is actually a web service. Go to ocr.space and select your file and language, then check the "Create searchable PDF with invisible text layer" option. Push the button and wait until the document is uploaded and converted.

Unfortunately, there is a bug for horizontal pages and they do not get rendered correctly in the output. I have notified the authors of this and they have acknowledged the problem.

  • Thanks a lot; it was years that I was looking for something as PDF Sandwich! – Marcolino Apr 7 at 12:55
  • 1
    @Marcolino you are welcome. Make sure to check out ocrmypdf as well. – Andrea Lazzarotto Apr 7 at 15:53
  • Useful this one, too. Thanks again! – Marcolino Apr 8 at 16:06

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.