2

I have some scanned magazines with a pink watermark on some of the pages. I need to ocr them and OCRmyPDF seems to be the right tool for the job. Except that it cannot convert text on top of the watermark.

I have prepared an example page which is already processed by ocrmypdf.

Lets try to search for the word "forbindelse" (connection in Danish) in the second line. You can find "forbind" but if you type the next letter, e, there is not match because the rest of the word is on top of the watermark.

Strangely enough it seems to have trouble converting text to the right of the watermark as well. For example, it cannot find the word "max" in line 8, but it finds "Output" in the same line because it comes before the watermark. You can also see it by double clicking on many words after the watermark. OCR'ed words are selectable, but these are not.

This is the command line:

ocrmypdf -l dan --skip-text --deskew --optimize 2 output.pdf output-ocr.pdf

I also tried with --remove-background but this option is not implemented.

Is there any way I can tweak the command to OCR the text on top of the watermarks?

1
  • Are you able to batch process the images before you OCR them? I would remove the watermark with color manipulation and then send them through OCR. Dec 12, 2022 at 17:02

2 Answers 2

0

The explanation : OCRmyPDF is making a real mess out of the OCR, and not only in the part around the watermark.

When trying to select all the elements in the first paragraph with my PDF editor, I get this :

enter image description here

You can see here an enormous number of text objects arranged in a mosaic, that give the effect of a continuous text. But this is not a real text paragraph, just a collection of well-positioned text-fragments. As an example, the word "forbindelse" was cut into two text boxes, so cannot be searched in its entirety.

It seems that OCRmyPDF might not the right tool for converting PDF to text. You may try your hand at tweaking its Advanced features, but I don't know this tool well-enough to suggest any.

For trying other tools, for conversion to text see the post Is there some sort of PDF-to-text converter?

This post suggests : pdftotext, pdf2line, calibre's ebook-convert, AbiWord, podofotextextract, pdf2ps with ps2ascii, Recoll. One of these would perhaps better suite your case.

If you wish the result to be an OCR'ed PDF, perhaps the best tool I know is Microsoft Word - simply opening the PDF will OCR the text. For other tools, see the post How to OCR a PDF file and get the text stored within the PDF?

You might also try some tools for erasing the watermark from the scanned images before doing the OCR, although I can't recommend any.

4
  • It looks like text fragments, but it is actually continuous text. If you Ctrl-A, Ctrl-C all text and paste it into an text editor, you will see that the text is continuous and well-formed for all words to the left of the watermark, but the parts after the watermark are missing. You can also search for continuous text, eg. "er meget velegnet i forbind". That wouldn't be possible if it was just text fragments in a mosaic that resembled continuous text.
    – marlar
    Dec 6, 2022 at 22:04
  • That's in the hands of the PDF viewer. You can't search for "forbindelse", and you can see in my image that the "else" part is a bit badly positioned as regarding the "forbind" part, which prevents the PDF viewer from treating it correctly as continuous text.
    – harrymc
    Dec 7, 2022 at 8:54
  • You can't even search for the "else" part. It is not ocr'ed. That's why you can only search for "forbind", because the rest is completely missing, it is not just misplaced.
    – marlar
    Dec 7, 2022 at 10:22
  • It seems to have become part of the background image - I can't select this part at all as an object in my text editor. The PDF created by OCRmyPDF is pretty weird already. I think that the best path for you is to erase the watermark in the original PDF before the OCR. There are products that do this.
    – harrymc
    Dec 7, 2022 at 10:46
0

In the given context there is no privacy issue, so before losing time on tweaking a tool, I'd try one of the numerous free online tools.

Google for "free pdf ocr online", then try 4-5 and see which one gives you the best result.

On the first try, I got a very good result with pdf24.org, which allows also automatic removing of background and artifacts.

enter image description here

RESULT: almost all words are OCR'd. Some scrambling remains enter image description here

2
  • Correct. privacy is not an issue. The problem is that I have a large number of old magazines to be OCR'ed and I would very much prefer to batch OCR them. However, I will check pdf24.org out. I guess the solution is to run the documents through a background remover tool and then OCR them afterwards.
    – marlar
    Dec 11, 2022 at 9:38
  • @marlar pdf24 is available as downloadable version with command line - although only for Windows. But maybe you can find a tool different from ocrmypdf, whoch works better
    – 1NN
    Dec 12, 2022 at 19:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .