On Wed, 30 Jan 2002, Ryan Novosielski wrote:

Here is the perl script that I uses to conver files to PDF and send the
PDF as an attachment.  The conversion from DVI > PDF produces some bad
looking fonts, but I suspect that is a problem with ghostscript.  The
troff wrapper is simply another script that uses grog which returns the
groff command that would produce postscript.  Feedback questions let me
know.

#!/usr/local/bin/perl -w

use Getopt::Std;
use MIME::Lite;

use strict;
use diagnostics;
MIME::Lite->send( "sendmail", "/usr/sbin/sendmail -t" );

#LPRng Filter Options
#Control File Filter Option Purpose or Value
#        -PPrinter   Print queue name - printcap information
#H       -HHost      Host Name
#P       -nUser      User Login Name of job originator
#J       -JJob name  lpr -J option or file name
#C       -CClass     Print class (lpr -C option)
#L       -LBanner    Banner page request
#A       -AJobid     Job Id
#D       -DDate      Date or time information
#Q       -QQueue     Original Print queue job was sent to
#N       -NFilename  Filename
#f       -Ff         Format information for datafile

my %opt;
getopt( 'PHnJCLADQNFe', \%opt );

my $filename = $opt{N};
my $datafile = "/tmp/$$/datafile";
my $psfile = "/tmp/$$/psfile";
my $pdffile = "/tmp/$$/$filename.pdf";

my $filecmd = "/usr/bin/file";
my $a2ps = "/usr/bin/a2ps -q -B -1 -M Letter --margin=20 -l 81 
--prolog=fixed --borders=no -o-";
my $dvips = "/usr/bin/dvips -f";
my $troff = "/usr/local/libexec/filters/troff_wrapper";
my $gs = "/usr/bin/gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite 
-sOutputFile=$pdffile -c save pop -f";

mkdir( "/tmp/$$", 0755 ) || die "could not mkdir /tmp/$$: $!\n";
open( DATAFILE, ">$datafile" ) || die "$0 could not open file: $datafile: 
$!\n";

while( <STDIN> ) {
    print DATAFILE $_;
}
close( DATAFILE );

convert_PDF();

### Create a new multipart message:
my $msg = MIME::Lite->new(
         From     =>$opt{n} . '@princeton.edu',
         To       =>$opt{n} . '@princeton.edu',
         Subject  =>'Your document [' . $filename . '] has been converted PDF',
         Date     =>`date`,
         Type     =>'application/pdf', 
         Encoding =>'base64',
         Path     =>$pdffile );
             
$msg->send;
 
if( -e $datafile ) { unlink( $datafile ); }
if( -e $psfile ) { unlink( $psfile ); }
if( -e $pdffile ) { unlink( $pdffile ); }
rmdir( "/tmp/$$" );
exit 0;

sub convert_PDF {
    my $filetype = `$filecmd $datafile`;
    if( $filetype =~ /postscript/oi ) {
       `$gs $datafile`;
    }
    elsif( $filetype =~ /roff/oi ) {
       `$troff < $datafile > $psfile`;
       `$gs $psfile`;
    }
    elsif( $filetype =~ /text/oi ) {
       `$a2ps < $datafile > $psfile`;
       `$gs $psfile`;
    }
    elsif( $filetype =~ /dvi/oi ) {
       `$dvips < $datafile > $psfile`;
       `$gs $psfile`;
    }
}


> Care to share? I'm thinking about doing this very shortly.
> 
> >
> > I just set up this exact same thing.  I created a perl script to convert
> > the source file to postscript and the ran ghostscript to convert the file
> > to PDF, then email the file to the user as an attachment.  All the
> > conversions and Email attachments are done within the perl script.
> >


Rob Fausey.

These are not the droids you're looking for.  Move along.  Move along.



-----------------------------------------------------------------------------
YOU MUST BE A LIST MEMBER IN ORDER TO POST TO THE LPRNG MAILING LIST
The address you post from MUST be your subscription address

If you need help, send email to [EMAIL PROTECTED] (or lprng-requests
or lprng-digest-requests) with the word 'help' in the body.  For the impatient,
to subscribe to a list with name LIST,  send mail to [EMAIL PROTECTED]
with:                           | example:
subscribe LIST <mailaddr>       |  subscribe lprng-digest [EMAIL PROTECTED]
unsubscribe LIST <mailaddr>     |  unsubscribe lprng [EMAIL PROTECTED]

If you have major problems,  send email to [EMAIL PROTECTED] with the word
LPRNGLIST in the SUBJECT line.
-----------------------------------------------------------------------------

Reply via email to