Using a Perl script backend to handle a printfile
David Coventry
dgcoventry at gmail.com
Sun Mar 8 09:00:49 PDT 2009
I have placed a simple Perl script in /usr/lib/cups/backed
=============================== snip ===================================
#!/usr/bin/perl -w
use strict;
if (!$ARGV[0]){
print "PDF emailer\n";
exit 0;
}
if (scalar(@ARGV) < 5 || scalar(@ARGV) > 6){
print STDERR "ERROR: Usage: mailpr job-id user title copies options [file]";
exit 1;
}
my ($jobID, $userName, $jobTitle, $copies, $printOptions, $printFile) = @ARGV;
open (OUT,">/tmp/test.prn") or die "ERROR: Bad news, I'm afraid: $!\n";
print OUT "$jobID, $userName, $jobTitle, $copies, $printOptions, $printFile\n";
while(<STDIN>){
print OUT "$_";
}
close OUT;
exit 0;
================================ snip ===================================
I have called the script 'mailpr'.
I have activated the printer using the following command:
lpadmin -p pdfmailer -v mailpr:/var/spool/cups/pdf/ -D "Generate PDF files to email" -E
This creates a printer in Cups called pdfmailer which uses the script mailpr as expected: a file is generated in /tmp/test.prn and it contains jobno, user, filename etc.
However, the print file is generated in /va/spool/cups and not in /var/spool/cups/pdf as I would expect. Also the filename as passed to /tmp/test.prn is of the order /var/spool/cups/d00014-001 as opposed to the actual file generated, which is /var/spool/cups/c00014. Furthermore the file does not contain raw text as expected.
Can anyone suggest how I can:
a) make sure that the script is passed the correct file name and
b) ensure that the file generated is plain text.
I need to read in the raw text file and, depending on the layout of the file, I want to mix it with a postscript background before ultimately creating a pdf to be emailed.
Many Thanks,
Dave Coventry
More information about the cups
mailing list