#!/usr/local/bin/perl
# Require Perl5
#
# pdfprint -- a perl script to print PDF files,
#
# by Fabrizio Pivari <pivari@geocities.com> 22 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 1.2.
#
use strict;
use Getopt::Long;

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

do GetOptions("configure=s" => \$configure,
              "help"        => \$help,
              "verbose"     => \$verbose) || printusage() ;
@elem=("pdf2ps","print");
%option=(pdf2ps             => '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);

my @args;
my $x=""; my $file="";
if (@ARGV) {
  foreach $x (@ARGV) {
    if ($x=~/\.pdf$/i) {
      $file="printpdf$$.ps";
      $verbose and print "Using pdf2ps tool with $x file\n";
      @args=("$option{'pdf2ps'}","$x","$file");
      system(@args) == 0 or die "system @args failed: $?";
      $verbose and print "Printing the $x file\n";
      @args=("$option{'print'}","$file");
      system(@args) == 0 or die "system @args failed: $?";
      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
    -configure file              defult 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

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);
}
