#!/usr/local/bin/perl use strict; use warnings; use Getopt::Std; use vars qw/$opt_h $opt_o $opt_r $opt_t/; my $scanimage = '/usr/bin/scanimage'; my $convert = '/usr/bin/convert'; getopts('ho:r:t:'); if ($opt_h) { print STDERR <.pdf) -r : (resolution) Scan at this resolution (default 120) -t : (tempdir) Temporary directory to use (default /tmp) END exit 0; } my $pdfname = $$; $pdfname = $opt_o if $opt_o; $pdfname =~ s/\.pdf$//i; my $res = 120; $res = $opt_r if $opt_r; my $tmp = '/tmp'; $tmp = $opt_t if $opt_t; my $pwd = $ENV{PWD}; mkdir "$tmp/$$.tmp" or die $!; chdir "$tmp/$$.tmp" or die $!; system(qq{$scanimage --batch=page%04d.pnm --mode Binary --resolution $res --source "Automatic Document Feeder"}); unless (system(qq{$convert -adjoin *.pnm $pdfname.pdf})) { open(PDFIN, "<$pdfname.pdf"); open(PDFOUT,">$pwd/$pdfname.pdf"); print PDFOUT ; close PDFOUT; close PDFIN; unlink("$pdfname.pdf"); unlink(glob('*')); chdir($pwd); rmdir("$tmp/$$.tmp"); exit 0; } else { print STDERR "$0 error on convert; please clean up $tmp/$$.tmp manually.\n"; exit 1; }