English
Deutsch
  

Code


About Matthias Nott
Business Objects
Picture Galleries
Code
Technical
Download





Locations of visitors to this page

I have an Adaptec SlimSCSI 1460 PCMCIA adapter that hooks into my Thinkpad T41p. I've connected a HP ScanJet 6100c to that Adapter. Unfortunately, the SCSI cable delivered with the AHA 1460 is extremely short, so that I once run into intermittent SCSI bus resets only because the cable was not hooked exactly into the PCMCIA card (the difference was hardly visible).

 

Anyway, scanning works fine. I use the following Perl script that I call from any directory to scan multiple pages into one PDF. I can change the resolution and the color depth from page to page:

  1. #!/usr/bin/perl
  2. #
  3. # This script scans a multipart image into a pdf
  4. #
  5. use strict;
  6.  
  7. my ($output) = join(" ", @ARGV);
  8.  
  9. #
  10. # Define the scanner here.
  11. #
  12. my $scanner = "hp:/dev/sg0";
  13.  
  14. #
  15. # Define the scan parameters here.
  16. #
  17. # Valid modes are:
  18. # Lineart|Halftone|Grayscale|Color
  19. #
  20. my $xres = "210mm";
  21. my $yres = "297mm";
  22. my $left = "0mm";
  23. my $top  = "0mm";
  24. my $mode = "Lineart";
  25. my $res  = "200dpi";
  26. my $light = "0";
  27. my $dir  = "/tmp/scan";
  28. my $file = "\@tmpscan";
  29. my $time = `date +"%Y%m%d"`; chomp($time);
  30.  
  31. #
  32. # Get the output file name and timestamp
  33. #
  34. if($output eq "") {
  35.   print "Enter the Filename (.pdf will be appended) [scan]       : ";
  36.   chop (my $output = <STDIN>);
  37. }
  38.  
  39.  
  40. if($output !~ /^.*\s-\s\d\d\d\d\d\d\d\d$/ && $output !~ /^.*\s-\s\d\d\d\d\d\d\d\d\.[pP][dD][fF]$/) {
  41.   print "Enter the Timestamp [$time] (n for none)             : ";
  42.   chop (my $tmptime = <STDIN>);
  43.  
  44.   if($tmptime ne "n") {
  45.     if($tmptime ne "") {
  46.       $output .= " - $tmptime";
  47.     } else {
  48.       $output .= " - $time";
  49.     }
  50.   }
  51. }
  52.  
  53. if($output =~ /^(.*)\.[pP][dD][fF](.*)$/) {
  54.   $output = "$1$2.pdf";
  55. } else {
  56.   $output .= ".pdf";
  57. }
  58.  
  59. #
  60. # Eventually create the working directory
  61. #
  62. if (!-d $dir) {
  63.   system("mkdir $dir");
  64. }
  65.  
  66. #
  67. # Scan the pages
  68. #
  69. my $next = "";
  70. my $page = 0;
  71. getFormat($mode, $res);
  72. do {
  73.   $page++;
  74.   system("scanimage -d $scanner --format pnm -x $xres -y $yres -l $left -t $top --mode $mode --brightness $light --resolution $res >\"$dir/$file$page.pnm\"");
  75.   $next = getFormat($mode, $res);
  76. } while ($next ne "q");
  77.  
  78. #
  79. # Convert to pdf
  80. #
  81. system("convert \"$dir/$file*\" -adjoin \"$output\"");
  82.  
  83. #
  84. # Clean up the scanned pages
  85. #
  86. system("rm \"$dir/$file\"*");
  87.  
  88. #
  89. # Open the file
  90. #
  91. system("acroread \"$output\" &");
  92.  
  93.  
  94.  
  95. #
  96. # Get the color depth
  97. #
  98. sub getFormat {
  99.   my ($curmode, $curres) = @_;
  100.  
  101.   print "Enter the next page Format: LHGCXXX [".substr($curmode,0,1).substr($curres,0,length($curres)-3)."], q to finish : ";
  102.  
  103.   chop (my $format = <STDIN>);
  104.  
  105.   if($format =~ /^([lLhHgGcC])(.*)$/) {
  106.     if(uc($1) eq "L") {
  107.       $mode = "Lineart";     
  108.     } elsif (uc($1) eq "H") {
  109.       $mode = "Halftone";
  110.     } elsif (uc($1) eq "G") {
  111.       $mode = "Grayscale";
  112.     } elsif (uc($1) eq "C") {
  113.       $mode = "Color";
  114.     }
  115.     if($2 ne "") {
  116.       $res = "$2dpi";
  117.     }
  118.     return "";
  119.   } elsif ($format =~ /^[qQ]$/) {
  120.     return "q";
  121.   }
  122. }
 


19.01.2006, 14:49 Copyright © 2005 MN Soft Industry Software, 108, route de la Fin, CH-1874 Champéry
Tel.: +41 797 844554; Fax: +41 860 797 844554, Responsible: Matthias Nott., mn(at)mnsoft.org
Top of Page