![]() |
Good luck, Brent
#!/usr/bin/perl ########################################################################## # printfax by Brent Davidson Copyright 2008 # This file is licensed under the terms of the GPL # This script is an add-on for Hylafax that automatically # resizes all pages to fit on a single paper size or # checks each page of a fax and applys an option to lpr # that specifies the paper size. # This program requires ImageMagick ######################################################################### use strict; use warnings; use File::Glob qw(:globally :nocase); my $file = $ARGV[0]; my $mode="resize"; #Set to noresize to print on legal or letter sized paper my $printer = 'Fax01'; # Set the name of the printer you wish to print to here. if ($mode eq 'resize') { resize ($file); }elsif ($mode eq 'noresize') { noresize ($file); } sub resize { my $file = shift @_; my ($fname,$ext) = split (/\./,$file); my $newfile = $fname.'_resized.tif'; # The line below does the resizing. The -resize x2100 tells convert # to resize the image to be only 2100 lines long and only if they # are larger than 2100 lines long. At 200DPI this is # just short of 11 inches, which is letter size paper. Using only a # height parameter to resize will maintain aspect ratio on the resize. # The "-monochrome -compress group 4" makse sure we keep a B&W TIFF # file with CCITT Group4 compression to keep tiff2ps happy. # if you wanted to fit everything to A4 size paper you would change the # x2100 to x2300 (2338 would be full A4 size. 2300 leaves a small # margin so the printer won't crop the page.) The first -resize x200% # is to correct for the non-square pixels used by fax machines. # See the documentation for ImageMagick for further options to the # convert command. system ("/usr/bin/convert $file -resize x200%! -resize x2100 -monochrome -density 204x196 $newfile"); my $psfile = $fname.'_resized.ps'; system ("tiff2ps -a $newfile > $psfile"); unlink ($newfile); chmod (0666,$psfile); system ("lpr -P $printer -r -o media=\"letter\" $psfile"); # I chose to run lpr against the ps file rather than pipe # the tiff2ps output to lpr's STDIN so the printer # would display the name of the file it is currently printing } sub noresize { my $file = shift @_; my ($fname,$ext) = split (/\./,$file); my $cnvformat = $fname."_"."%02d".".tif"; # This line splits the tif file into individual pages system ("convert $file -resize x200%! -monochrome -compress group4 $cnvformat"); my $globspec = $fname."_"."*.tif"; foreach my $page (glob ($globspec)) { my $size = `identify -format "%w %h" "$page"`; chomp $size; my ($width,$height) = split (' ',$size); my $paper_size; # We check the height based on 200DPI x 11 inches + a small margin for error. # If you need more/other paper sizes you can chain in more if statement or # change the comparison number. For example an A4 wpage ould be 2338 lines # so you could change the line below to something like $height > 2400 to # check for A4 size paper. # You will also need to change the value assigned to $paper_size. See the # man page for lpr to see what sizes are valid. if ($height > 2300) { $paper_size = "legal"; }else { $paper_size = "letter"; } system ("tiff2ps $page | lpr -P $printer -o media=$paper_size"); unlink ($page); } }