[Samba] Re: pdf printer

Matthew Western
Tue, 03 Jun 2003 23:03:52 -0000

lol.  sure thing....    mine emails to the user that created it as there
we're politics about everyone seeing everyone elses .pdfs on a fileshare or
webserver.  i put it on a webserver nobody knew was there so i could easily
forward the pdf on if it failed to attach to the email.

also, i'm thinking about replacing the text 'Microsoft Word - ' etc
with
nothing as well.  you'll see what i mean when you test it.

oh yeah.  mine broke when i upgraded ghostscript hence the slamming of a few
TMPs in there.  that fixed it.  <sigh>  i wish ghostscript people would do
some nice error messages, not something like "*** Unable to open the
initial
device, quitting."

regards
Matthew

-------------------
#!/bin/sh
#
# 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@imec.be) 2001
LOGFILE=/var/log/cups/pdf.log
PDFBIN=`which ps2pdf`
FILENAME# this is borrowed from printpdf script for the filename
PRINTTIME=`date +%b%d-%H%M%S`
#at the moment it's setup to email the pdf but not email the link to the
webserver.
DOMAIN="@yourdomain.com.au"
WEBSERVER="http://calypso/pdf/"
TEMP="/tmp"
TMP="/tmp"
TMPDIR="/tmp"
TEMPDIR="/tmp"

#mail stuff
DATE=`date +%d%b%Y-%H:%M:%S`
MAILFILE=/tmp/mailtemp
HEADER=/tmp/header


# case of no argument, prints available URIs
if [ $# -eq 0 ]; then
	if [ ! -x "$PDFBIN" ]; then
		exit 0
	fi
	echo "direct pdf \"Unknown\" \"PDF Writing\""
	exit 0
fi

# case of wrong number of arguments
if [ $# -ne 5 -a $# -ne 6 ]; then
	echo "Usage: pdf job-id user title copies options [file]"
	exit 1
fi

# get PDF directory from device URI, and check write status
PDFDIR=${DEVICE_URI#pdf:}
if [ ! -d "$PDFDIR" -o ! -w "$PDFDIR" ]; then
	echo "ERROR: directory $PDFDIR not writable"
	exit 1
fi

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
echo "TEMP=$TEMP" >> $LOGFILE

FULLTITLE=`grep Title $6`
TITLE=${FULLTITLE:9}

#replace all not allowed characters with a _  - could do it with a regular
expression but too hard_
#      \ / : * ? " < > |

TITLE=${TITLE//:/_}
TITLE=${TITLE//\//_}
TITLE=${TITLE//</_}
TITLE=${TITLE//>/_}
TITLE=${TITLE//|/_}


echo "fulltitle: "$FULLTITLE >> $LOGFILE
echo "chopped: "$TITLE >> $LOGFILE



# generate output filename
OUTPUTFILENAMEif [ "$3" = "" ]; then
	OUTPUTFILENAME="$PDFDIR/unknown.pdf"
else
	# OUTPUTFILENAME="$PDFDIR/${3//[^[:alnum:]]/_}.pdf"
	# 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
title.
	# OUTPUTFILENAME="$PDFDIR/$2-$PRINTTIME.pdf"
	OUTPUTFILENAME="$PDFDIR/$TITLE.pdf"

	echo "PDF file: $OUTPUTFILENAME placed in: $PDFDIR" >> $LOGFILE
fi

echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE

# run ghostscript
if [ $# -eq 6 ]; then
	$PDFBIN  -sPAPERSIZE=a4 $6 "$OUTPUTFILENAME"

# echo "	$PDFBIN -sPAPERSIZE=a4 $6 /tmp/3.pdf " >> $LOGFILE
# 	$PDFBIN $6 /home/mwestern/3.pdf >> $LOGFILE

 echo "Outputing PDF: $PDFBIN $6 $OUTPUTFILENAME" >> $LOGFILE

cp $6 /tmp/5.ps
ps2pdf /tmp/5.ps /tmp/6.pdf >> $LOGFILE

#	$PDFBIN  $6 "$OUTPUTFILENAME"
#>& /dev/null

else

 echo "unknown User output" >> $LOGFILE

	$PDFBIN -sPAPERSIZE=a4 - "$OUTPUTFILENAME" >& /dev/null
fi

# 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"
fi


#Sendmail to the owner.
echo "Sending mail: "$2$DOMAIN >> $LOGFILE

TO=$2$DOMAIN
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
message \
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

rm $MAILFILE
rm $HEADER


exit 0




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

-----Original Message-----
From: Bob Crandell [mailto:bob@assuredcomp.com]
Sent: Wednesday, June 04, 2003 12:55 AM
To: mwestern@sola.com.au
Subject: RE: [Samba] Re: pdf printer


<Singing>
I want that script.
</Singing>

Thanks


mwestern@sola.com.au wrote:
>
>did you end up figuring this out?  i have a working cups pdf printer.
>thanks to some guy who posted to here....
>
>i've modified my pdfprinter to email the user as well, sing out if you
want
>that script....
>
>-------------------------------------------------------------------
>>Using CUPS backend to create PDF virtual printer
>>---------------------------------------------------------------
>>---------
>>
>>1. Get a un*x box with CUPS and ghostscript set up on it.
>>
>>2. Go here: http://printing.kde.org/downloads/ and download
>>this backend
>>script: http://printing.kde.org/downloads/pdfdistiller
>>
>>3. Log in as root, put it in /usr/lib/cups/backend or wherever
>>cups/backend lives.
>>
>>4. 'chmod +x' the file (should be 755: rwxr-xr-x).
>>
>>5. Restart CUPS ('service cups restart' or appropriate).
>>
>>6. To check if CUPS recognizes it as a usable backend, let root run:
>>      'lpinfo -v | grep pdf'
>>    should output "direct pdf"
>>
>>7. Test the pdfdistiller backend:
>>     a. '/usr/lib/cups/backend/pdf'
>>     	should output 'direct pdf "Unknown" "PDF
Writing"'
>>     b. "/usr/lib/cups/backend/pdf 1 2 a b"
>>       should output: "Usage: pdf job-id user title copies
>>options [file]"
>>
>>8. Test existence of Ghostscript's ps2pdf with 'which
ps2pdf'. Output
>>should be a path like "/usr/bin/ps2pdf" or similar
>>
>>9. Download a PPD file for cups to print with. An Adobe
>>Distiller PPD is
>>a great choice. I used the one from this page:
>>
>>http://www.pentondigitalads.com/PentonDigitalAds/creating_posts
>cript_files.h
>tm
>("Acrobat Distiller PPD for Windows")
>     If this link is dead, search Google/web for "distiller ppd"
and
>find a suitable file.
>
>10. Put the PPD file in /usr/share/cups/model or wherever your CUPS
>model PPDs are stored.
>
>11. Restart CUPS.
>
>12. Add the printer to CUPS with the command:
>     'lpadmin -p <Chosen Name> -E -v pdf:<out folder> -m
<ppd-file>'
>      i.e.:
>     'lpadmin -p PDFprinter -E -v pdf:/pub/pdf_out -m distiller.ppd'
>
>13. Test the PDF output by manually printing to the new printer:
>     'lpr -P PDFprinter test.txt'
>
>Troubleshooting each step:
>
>1. If you're stuck on #1, find a more appropriate howto.
>
>2. If that file is missing, beg someone for a copy.
>
>7. I got stuck on this one. without renaming it "pdf", it
didn't work at
>all. No clue why. Try copying the file "pdfdistiller" the file to
"pdf"
>in the same folder. ('cp pdfdistiller pdf'). If these aren't
working, go
>no further. Make sure CUPS is installed properly and work on this first.
>
>8. If this doesn't work, you'll need to install the latest "ESP
>Ghostscript". It's available at:
>
http://www.cups.org/software.php
>
>9. Adobe doesn't distribute this file, so it could be tricky to find.
>
>10. Same as #3. PPD files made for Macintosh and Windows computers will
>need to be re-saved in un*x format.
>
>11. There should be a number of PPD files in that folder already. Search
>for "laserjet.ppd" if you have no idea where to find them.
>
>12. If this fails, make sure you're specifying a valid PPD file from the
>model folder in the "-m" part. Alternatively, you may use '-P
<ppd>'
>instead of '-m', but you must specify the entire path.
>
>13. No go? Time to start logging everything. After the first line of
>your backend file (pdf or pdfdistiller), add the line "set -x".
Edit
>your cupsd.conf and set "LogLevel debug". Restart CUPS and peruse
the
>information in /var/log/cups/error_log for good debugging info.
>
>Enjoy!
>
>Thanks to Kurt Pfeifle [kpfeifle (at) danka (dot) de] for all the help,
>comments and editing this mini-howto with me.
>
>
>---------------------------------------------------------------
>
>-----Original Message-----
>From: samba-bounces@lists.samba.org
>[mailto:samba-bounces@lists.samba.org]On Behalf Of Norman Zhang
>Sent: Saturday, May 31, 2003 9:04 AM
>To: samba@lists.samba.org
>Subject: [Samba] Re: pdf printer
>
>
>Hi,
>
>Thank you for your reply.
>
>> Please use this little HOWTO:
>>
>>     http://lists.samba.org/pipermail/samba/2003-March/093504.html
>>
>> The "color" all depends on the PPD you are using. If you use
a B/W
>Laerprinter
>> PPD for this, your PDF will be B/W too. The suggested distiller.ppd
should
>> be alright. Do you get B/W or Color PDFs from Linux/UNIX/CUPS?
>
>I followed the exact procedure as per above URL, except I grabbed the
>adist5.ppd from the Adobe Universal PostScript Installer 1.0.6. Is that
>okay? CUPS seems to able to read it. I got color PDF when I installed an
>arbitrary color laser printer (HP Color LaserJet 8500 PS. I thought I can
>get different paper size with this model) and B/W with a B/W laser printer
>(HP LaserJet 2200 PS). Do you have a recommendation for a particular model?
>
>> > I have another question, do I need to add a Color Laser Printer
Driver
>in
>> > W2K to the PDF share to generate color PDF in Windows?
>>
>> If you read the suggested HOWTO, you'll see that the driver
installation
>> first takes place on CUPS. Then you have a CUPS PDF printer (also
>accessible
>> to native CUPS clients).
>
>I have setup CUPS to use PDF printing. I guess I just need to add printer
>drivers to the queue? I was adding the drivers from W2K using HP's
printer
>drivers. I know it is better to use CUPS drivers, but I don't know which
>model is good and it seems to be difficult to use cupsaddsmb.
>
>> To install it on W2K, simply download the CUPS driver. Before you
download
>> it, you need to run cupsaddsmb. Before you run cupsaddsmb, you should
read
>> "man cupsaddsmb". Even more info about it is here:
>>
>>    http://www.linuxprinting.org/kpfeifle/SambaPrintHOWTO/
>
>I have been reading your document for the last 2 days (excellent document
>BTW). I guess I will read it again 8)
>
>Regards,
>Norman
>
>
>
>
>

--
Bob Crandell
Assured Computing
When you need to be sure.
bob@assuredcomp.com
www.assuredcomp.com
Voice - 541-689-9159
FAX - 541-463-1627
Eugene, Oregon