I use gscan2pdf every month, mostly to scan bills. I keep each vendor's bills in a separate directory. I could save myself some time if gscan2pdf were to make an educated guess at what directory an image belongs in. Since it doesn't do that, I wrote a script that uses scanimage, tesseract, convert, and grep to scan in the image, extract the text, pattern-match the text, and map that match to a directory name. It works great except that producing an image with scanimage and then converting that image to a PDF consistently produces a PDF that's twice as big as what gscan2pdf produces.
As far as I can tell, gscan2pdf uses scanimage internally, but I'm not very good at reading Perl code.
TL;DR: how can I configure scanimage to produce PDFs as small as gscan2pdf's?
- Ubuntu 13.04
- gscan2pdf 1.2.2
- scanimage (sane-backends) 1.0.23; backend version 1.0.23
- convert Version: ImageMagick 6.7.7-10 2013-09-10 Q16 http://www.imagemagick.org; Features: OpenMP
The typical document is an 8.5 x 11 bill, white background with some kind of logo up top, and black text. I've tried various scan resolutions (100dpi, 200dpi, 400dpi) and both scanimage formats (PPM and TIFF).
Here is the part of the script that scans and converts (I omitted the text extraction and pattern-matching part):
#!/bin/bash rm -f /tmp/scanned* /tmp/united.pdf echo -n "Scanning..." scanimage --batch=/tmp/scanned%d.ppm --format=ppm 2> /tmp/scanned.err # PDFs are way too big if you convert from PPM, so convert PPM -> JPG first echo -n "converting to PDF..." for file in /tmp/scanned*.ppm; do convert $file $file.jpg 2>> /tmp/scanned.err convert $file.jpg $file.jpg.pdf 2>> /tmp/scanned.err done # pdfunite doesn't work with single PDF echo -n "concatenating pages..." COUNT=$(ls -1 /tmp/scanned*.pdf|wc -w) if [ $COUNT -eq 1 ]; then cp /tmp/scanned*.pdf /tmp/united.pdf else pdfunite /tmp/scanned*.pdf /tmp/united.pdf fi