Scan 2 PDF

Get the free and open source app Open Note Scanner from F-Droid. It will download Open CV, an open source AI app for automatically recognize page edges.

I want to get perfect black and scans. My settings (anything else is disabled):

  • PNG (cog symbol)
  • Black and white (top menu)
  • Manual mode (top menu)
  • Probably activate image post-processing (top menu)

My phone utilizes the Nextcloud app with automatically upload new files settings enabled.

If page edges can’t be identified, press the button twice for taking an image from the entire screen. Find additional information at the bottom of this post.

Case 1

You got your PNG images uploaded to your Nextcloud instance. All those images are in sync with your Windows / Linux / Mac computer.

This is a tutorial for Linux / ubuntu users. If you use ubuntu, or another Debian based system, installing all needed programs is done within seconds.

sudo apt install imagemagick
sudo apt install img2pdf
sudo apt install tesseract-ocr
sudo apt install ocrmypdf
# the beneath package for German words recognition
sudo apt install tesseract-ocr-deu

You may want to compress all PNGs as strong as possible. Notice, I have created the sub-folder temp first.

for i in `ls *.png`; do convert $i -quality 90 ./temp/$i; done

Add all PNGs to one PDF. The page order is already set by the file names.

img2pdf --output new.pdf --pagesize a4 `ls ./temp/*.png`

Case 2

A leaflet, a book, or whatever you need to scan with two pages at once.

All PNGs are uploaded to Nextcloud, all these files are synchronized with your PC.

Extract these two pages from each PNG. Create a sub-folder with the name cropped.

COUNTER=0; for i in `ls *.png`; do COUNTER=$[COUNTER +1]; convert +repage -crop 50%x100% $i ./cropped/$COUNTER.png; done

You want to rotate your pages?

# 90, 180, -90
for i in `ls *.png`; do convert -rotate 90 $i ./temp/$i; done

For a stronger compression, create a sub-folder with the name temp, call the following command.

for i in `ls *.png`; do convert $i -quality 90 ./temp/$i; done

Create a PDF.

img2pdf --output new.pdf --pagesize a4 `./temp/*.png`

Case 3

You want to add an ocr layer to each PDF page.

ocrmypdf -l deu+eng --output-type pdf new.pdf new2.pdf

Note, „deu“ stands for German. In this case, tessaract recognizes all English and German words in one PDF.

Additional Information

I mentioned above that you probably need to cut out pages. My way to do so is by using Gimp. Just select the page, copy-paste to a new image, overwrite the original image with the same name.

My local knowledge base is easily to crawl through by Recoll. Because of adding an ocr layer to each page (Case 3), Recoll finds all words in the PDF within a friction. Also, I can select „snippets“ to see each page number where the word appears.