[plug] CUPS pipe:/ Options?

Ryan ryan at is.as.geeky.as
Mon Aug 8 09:00:45 WST 2005


On Mon, 2005-08-08 at 08:17 +0800, Bernd Felsche wrote:
> I need to have a program handling "print" jobs.
> 
> CUPS provides for a pipe:/ process to handle print jobs but the
> documentation is not clear on how to pass options to that process.
> Nothing "telling" in the environment and no process arguments.

Consider a backend.  Here is one we prepared earlier (makes PDFs).

I know Craig made lots more changes, as did I, but all I have now is
this original barely surviving beta :)

------------------------------------

#!/usr/bin/perl

# CUPS PDF Writer Backend
#
# December 2002
# Craig Ringer and Ryan Armanasco
#
# License: GPL
#
# Version: ***SERIOUSLY*** Beta
#
# Firstly some explanation:
#
# This is a Perl executable that CUPS considers a backend when you stick
# it in /usr/lib/cups/backend (or equivalent in your distribution)
#
# CUPS creates a temporary file of the print job, the location of which
it
# passes as the 6th arguement to this script.
#
# This file is a postscript file and is read in and sent to ps2pdf to
create
# the PDF file
#
# CUPS expects this script to output certain information to correctly
# identify it as a backend when it is called with no arguements - this
is
# handled in the first few lines of code.
#
# The arguements passed to this script by cups are:
#
# 459 | burrol | ScanImage01 | 1 |  | /var/spool/cups/d00459-001
#
# $ARGV[0] - print job number
# $ARGV[1] - username
# $ARGV[2] - print job name
# $ARGV[3] - page count i think
# $ARGV[4] - i forget now - it is always blank though
# $ARGV[5] - temporary print job location

use strict;
use vars qw();

# DEBUG stuff - last minute - no error checking :)
system('env > /tmp/pdfenv');

# CUPS server uses this to identify backends
# backends are required to spit this out when
# no arguements are given
if ( scalar(@ARGV) == 0 ) {
        print "network pdffile \"Unknown\" \"PDF File output\"\n";
        exit;
}
undef $/;

# get ready to log stuff - who knows why we named it ERRLOG :)
open(ERRLOG,'>/tmp/pdferr') or die "failed to open error log: $!\n";

print ERRLOG join(' | ', at ARGV);
print ERRLOG "\n".$ARGV[1];

# if the PDF directory exists for the designated user:
if ( -d "/users/".$ARGV[1]."/PDF") {

# strip possible bad chars from print job name: \ / : ; " ' < > * ? | .
$ARGV[2] =~ s#[\\\/:;"`<>\*\?\|\.]#_#g;

# prepare the deed
open(PS2PDF,'|/usr/bin/ps2pdf
- /users/'.$ARGV[1].'/PDF/"'.$ARGV[2].'.pdf"')
        or print ERRLOG "Arrggh, failed to open pipe to ps2pdf: $!\n",
exit;
}

# open the temporary file CUPS creates of the print job
open(CUPSSPOOL,$ARGV[5])
        or print ERRLOG "couldn't open $ARGV[5]: $!\n", exit;

# spit the print job at ps2pdf
print PS2PDF scalar(<CUPSSPOOL>);

#finish off
close(PS2PDF)
        or print ERRLOG "Failed to close pipe to ps2pdf: $!\n", exit;
close(CUPSSPOOL)
        or print ERRLOG "failed to close $ARGV[5]: $!\n", exit;
close(ERRLOG);

# END
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.plug.org.au/pipermail/plug/attachments/20050808/b95b6aaf/attachment.pgp>


More information about the plug mailing list