[Samba] Modified Cups Backed pdf writer to keep the original
mwestern at affairs.net.au
Fri May 16 05:03:29 GMT 2003
I've got a samba/cups pdf writer going thanks to PeteFwee and Wolfram Q and
a few others... the cups pdf backed i used has a default of
username-date.pdf which I didn't like and wanted the name of the job that
got send in the printer q on the winslows client.
The only way I could see in my very limited experience was to grab the
%%Title out of the postscript file and make sure that it didn't have any bad
I also did a few extra lines to send the .pdf to the person that sent it
(thankfully that was already passed though).
Here it is. I didn't use awk when i probably should of because i'm crap at
regular expressions. Real programmers might have a laugh and my error
checking is non-existant, but it worked for me and may be useful to some
newbie out there somewhere....
thanks goes to Michael Goffioul for writing the orginal script which i got
http://printing.kde.org/downloads/pdfdistiller and the how to posted
originally to samba by Tom. i'd be interested in any feedback about how i
should have used awk so i can learn. :)
# This script is intended to be used as a CUPS backend, to create
# PDF file on-the-fly. Just create a printer using the device uri
# pdf:/path/to/dir/. When printing to this printer, a PDF file
# will be generated in the directory specified. The file name will
# be either "<jobname>.pdf" or "unknown.pdf", depending whether the
# jobname is empty or not.
# To use it, simply copy this script to your backend directory, and
# create a printer with the correct URI. That's it.
# Copyright (C) Michael Goffioul (goffioul at imec.be) 2001
# this is borrowed from printpdf script for the filename
# case of no argument, prints available URIs
if [ $# -eq 0 ]; then
if [ ! -x "$PDFBIN" ]; then
echo "direct pdf \"Unknown\" \"PDF Writing\""
# case of wrong number of arguments
if [ $# -ne 5 -a $# -ne 6 ]; then
echo "Usage: pdf job-id user title copies options [file]"
# get PDF directory from device URI, and check write status
if [ ! -d "$PDFDIR" -o ! -w "$PDFDIR" ]; then
echo "ERROR: directory $PDFDIR not writable"
echo "PDF directory: $PDFDIR" >> $LOGFILE
# Start of Matthew's modified stuff.
echo " " >> $LOGFILE
echo "Executable: $PDFBIN" >> $LOGFILE
echo "Arguments: |$1|$2|$3|$4|$5|$6|" >> $LOGFILE
echo $# $PRINTTIME >> $LOGFILE
echo "PS File: $6" >> $LOGFILE
FULLTITLE=`grep Title $6`
#replace all not allowed characters with a _ - could do it with a regular
expression but too hard_
# \ / : * ? " < > |
echo "fulltitle: "$FULLTITLE >> $LOGFILE
echo "chopped: "$TITLE >> $LOGFILE
# generate output filename
if [ "$3" = "" ]; then
# I changed this to user name, and the printtime to track down who
# printed the PDF and when, samba printing just uses nobody
# default is username and date. Matt modified to read the postscript
echo "PDF file: $OUTPUTFILENAME placed in: $PDFDIR" >> $LOGFILE
echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE
# run ghostscript
if [ $# -eq 6 ]; then
$PDFBIN -sPAPERSIZE=a4 $6 "$OUTPUTFILENAME"
# $PDFBIN $6 "$OUTPUTFILENAME"
$PDFBIN -sPAPERSIZE=a4 - "$OUTPUTFILENAME" >& /dev/null
# modify ownership and permissions on the file
# - world readable
# - owns to user specified in argument
chmod a+r "$OUTPUTFILENAME"
if [ "$2" != "" ]; then
chown $2 "$OUTPUTFILENAME"
#Sendmail to the owner.
echo "Sending mail: "$2$DOMAIN >> $LOGFILE
SUBJECT='PDF Printer Job'
BODY='PDF Created :'$DATE
#echo PDF Created: $DATE >> BODY
echo From: PDFPrinter$DOMAIN >> $HEADER
echo To: $TO >> $HEADER
#echo Cc: $CC >> $HEADER
#echo Bcc: $BCC >> $HEADER
echo Subject: $SUBJECT >> $HEADER
echo "" >> $HEADER
echo $BODY >> $HEADER
echo "" >> $HEADER
echo "" >> $HEADER
echo "If your PDF job is not attached to this email please forward this
to the help desk for assistance." >> $HEADER
echo "------------------" >> $HEADER
echo Filename: $OUTPUTFILENAME >> $HEADER
cat $HEADER > $MAILFILE
#uuencode "$OUTPUTFILENAME" $2-$PRINTTIME.pdf >> $MAILFILE
uuencode "$OUTPUTFILENAME" "$TITLE.pdf" >> $MAILFILE
cat $MAILFILE | /usr/lib/sendmail -t
More information about the samba