#!/usr/local/bin/perl
# Require Perl5
#
# pdfprint -- a perl script to print PDF files,
#
# by Fabrizio Pivari <pivari@geocities.com> 29 March 1998
#
# Copy, use, and redistribute freely, but don't take my name off it and
# clearly mark an altered version.  Fixes and enhancements cheerfully 
# accepted.
#
# This is version 2.0.
#
use strict;
use Getopt::Long;

my $version="2.0";
my $configure="pdfprint.cfg";
my $recursive="";
my $verbose="";
my $help="";
my @elem; my %option; my $elem="";

do GetOptions("configure=s" => \$configure,
              "recursive=s" => \$recursive,
              "help"        => \$help,
              "verbose"     => \$verbose) || printusage() ;
@elem=("converter","print");
%option=(converter             => 'pdftops',
         print              => 'lpr');

$help and printusage();

open (CNF, "$configure") || die "pdfprint: couldn't open configuration file $configure\n";
while (<CNF>) {
  s/\t/ /g;        #replace tabs by space
  next if /^ *\#/; #ignore comment lines
  next if /^ *$/;  #ignore empty lines
  foreach $elem (@elem) {if (/ *$elem *: *(.*)/i) {$option{$elem}=$1;}}
  }
close(CNF);

sub wanted {
    push @ARGV,$File::Find::name;
  }

if ($recursive) { 
  find (\&wanted,"$recursive");
  }

my @args;
my $x=""; my $file="";
if (@ARGV) {
  foreach $x (@ARGV) {
    if ($x=~/\.pdf$/i) {
      $file="printpdf$$.ps";
      $verbose and print "Using converter tool with $x file\n";
      `$option{'converter'} $x $file`;
      $verbose and print "Printing the $x file\n";
      `$option{'print'} $file`;
      unlink $file;
      } else {print "Warning: the extension of the file isn't .pdf or .PDF\n";}
    }
  }
else {printusage();}

sub printusage {
    print <<USAGEDESC;

usage:
        pdfprint [-options ...] files

where options include:
    -help                        print out this message
    -verbose                     verbose
    -recursive directory         scan recursively the directory
    -configure file              default pdfprint.cfg

files:
    with files you can use metacharacters and relative and absolute path name
    
example:
    pdfprint *.pdf
    pdfprint -v -c tests/test.cfg */*.pdf
    pdfprint -r pdfdocs

If you want to know more about this tool, you might want
to read the docs. They came together with pdfprint!

Home: http://www.geocities.com/CapeCanaveral/Lab/3469/pdfprint.html

USAGEDESC
    exit(1);
}
