Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

Version information:

  • 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
share|improve this question
    
Could you add the exact commands you are using (scanning, conversion) to question? –  Sneetsher Feb 4 at 0:43
    
@Sneetsher done. –  user100464 Feb 4 at 0:48
    
Try add -compress when converting to pdf. convert $file.jpg -compress jpeg $file.jpg.pdf 2>> /tmp/scanned.err –  Sneetsher Feb 4 at 0:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.