I tested 3 techniques on a 4-page A4 scanned doc, bilevel.
- pbm → PNG → pdf
- pbm → DjVu → pdf (← winner)
- pbm → TIFF → pdf (← nearly tied)
Using PNG as an intermediate format
$ unpaper -t pbm from_scanner.pbm deskewed.pbm
$ optipng --strip all -o7 -out intermediate.png deskewed.pbm; # better compression than ImageMagick
$ pdfjam --a4paper -o final.pdf intermediate.png; # contains png files as-is with no transcoding
That’s the general idea but done on 4 files and then ocr’d this way:
$ ocrmypdf viaPNG.pdf viaPNGocr.pdf
Using DjVu as an intermediate format
(starting with unpaper’d pbm files)
$ for f in *.pbm; do cjb2 -lossless -clean "$f" "${f%.*}".djvu; done
$ djvm -c viaDjVu.djvu *.djvu
$ ddjvu -format=pdf -quality=150 viaDjVu.djvu viaDjVu.pdf
$ ocrmypdf viaDjVu.pdf viaDjVuocr.pdf
Using TIFF as an intermediate format
(starting with unpaper’d pbm files)
$ for f in *.pbm; do pamtotiff -output "${f%.*}".tiff "$f"; done; #uncompressed tiffs by default
$ tiffcp *.tiff viaTIFF.tiff; #decompressed by default
$ tiff2pdf -F -p A4 -o viaTIFF.pdf viaTIFF.tiff
$ ocrmypdf viaTIFF.pdf viaTIFFocr.pdf; #lossless compression by default
It’s annoying that pamtotiff produces a grayscale tiff from a PBM, but it seems to sort itself out in the end.
Results
$ du -h *ocr.pdf
200K viaDjVuocr.pdf
320K viaPNGocr.pdf
200K viaTIFFocr.pdf
The viaDjVuocr.pdf is slightly smaller than viaTIFFocr.pdf when looking at byte size.
Good alternative approaches welcome!
You must log in or register to comment.
