Printing to files not supported?

Michael Sweet mike at easysw.com
Tue Aug 10 10:05:13 PDT 2004


Alex wrote:
> Did CUPS stopped supporting printing to files totally?  I know there
> is support for PDF's but is that all that is left?

CUPS has never truly supported printing to a file; there was (and
still is) some very limited support for "file:" device URIs for
testing purposes, but it was never designed for more than that.

The following script can be used to print to a file and optionally
email the job owner:

#!/bin/sh
#
# File printing backend script for CUPS.  Install in
# /usr/lib/cups/backend/tofile (/usr/libexec/backend/tofile on *BSD and 
OSX),
# make executable (chmod +x /usr/lib/cups/backend/tofile), and restart CUPS
# ("killall -HUP cupsd" or "service cups restart")
#
# Use a device URI of the form "tofile:/directory/path" to put print files
# in the corresponding directory.  Print files are created with names of
# the form:
#
#     printername.username.jobid
#
# This backend does not support copy generation.
#

# Verify that the command-line is of the form:
#
# tofile
# tofile job-id user title copies options
# tofile job-id user title copies options printfile

if test $# = 0; then
         # Show device info...
         echo 'direct tofile "Unknown" "Print To File"'
         exit 0
fi

if test $# -lt 5 -o $# -gt 6; then
         # Show usage...
         echo Usage:
         echo tofile
         echo tofile job-id user title copies options
         echo tofile job-id user title copies options printfile
         exit 1
fi

# Extract the output directory from the DEVICE_URI environment
# variable...

outdir=`echo $DEVICE_URI | awk -F: '{print $2}'`

if test ! -d "$outdir"; then
         echo "ERROR: Output directory '$outdir' does not exist!" 1>&2
         exit 1
fi

# Format the output filename from the printer, user, and job-id.
outfile="$outdir/$PRINTER.$2.$1"

# Copy the print file or standard input to the file...
if test $# = 5; then
         cat >>$outfile
else
         cat $6 >>$outfile
fi

# Change the permissions and ownership for the print user...
chmod 600 $outfile
chown $2 $outfile

# Insert any post-processing, such as emailing, here...

## Email to user
# su -c $2 Mail -s "$PRINTER.$2.$1" <$outfile

# All done, exit with status 0
exit 0

-- 
______________________________________________________________________
Michael Sweet, Easy Software Products           mike at easysw dot com
Printing Software for UNIX                       http://www.easysw.com




More information about the cups mailing list