[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SLUG] print to pdf

This isn't very amazing, and its been done before, 
but I think its useful.

Basically, the idea is you print to a samba print share,
and receive an email with a pdf file attached of your 
print job. So you can get any application (word, visio, project, cad, 
etc) to generate pdf files.

It assumes your username @nospam. somedomain is a valid email address.

I'm testing this on samba 2.2, but it should work on other

I followed the instructions in printer_driver2.html
(could be a different doc for other viersions)

Made a share like: (basically copied from smbfax)
        comment = Print to PDF
        path = /home/prnt2pdf/spool
        create mask = 0700
        printable = Yes
        postscript = Yes
        print command = /home/prnt2pdf/bin/print2pdf queue %u %s
        lpq command = /home/prnt2pdf/bin/print2pdf show
        lprm command = /home/prnt2pdf/bin/print2pdf dequeue %j
        queuepause command = /bin/true
        queueresume command = /bin/true

/home/prnt2pdf/spool needs to be writable to whoever is printing.

/home/prnt2pdf/bin/prnt2pdf Is a small shell script, it only does
the minimum to get it to work. Its a quick hack, no thought of
security, etc. 

# grab the title from the postscript file.
TITLE=`/usr/bin/head -n20 $DIR/spool/$PS | /bin/grep '%%Title:' | /usr/bin/awk -F':' {'print $2 ".pdf"'}`

if [ "$1" = "queue" ]
	# PPID is a dodgy way to get a unique dir, I'm just testing at 
	# the moment, so it will do for now.
	# $DIR/pdf has be writable to the user doing the printing.
        mkdir -p $DIR/pdf/$PPID
	# requires the gs package.
        /usr/bin/ps2pdf "$DIR/spool/$PS" "$DIR/pdf/$PPID/$PS.pdf"
	# Use the title from the postscript file as a filename if we can,
	# else use the temp file name samba gives us.
        if [ -z $TITLE ]
                mv "$DIR/pdf/$PPID/$PS.pdf" "$DIR/pdf/$PPID/$TITLE"

	# I had mutt installed already so I used it.
        /usr/bin/mutt -a "$DIR/pdf/$PPID/$TITLE" -s "print to pdf, file: $TITLE" $EMAIL </dev/null
        rm -rf $DIR/pdf/$PPID
        rm -f $DIR/spool/$PS


if [ "$1" = "show" ]
	# too lazy to do this, you just need to echo
	# rank fileowner "A" jobid filename filelength filetime
	# for each file in the spool dir.
	# I think the rank should be active or paused, etc.
	# I don't know what "A" means or does.

# dequeue, too lazy.

Than I added the printer to an NT box, installed a colour laser PS
driver, and print to it.

I've tried quite a few different apps, it gives acceptable results.
Tried a 4meg doc file with lots of pictures embedded, it produced
a 20meg ps file, and ps2pdf took about 4 minutes to produce a 10 meg
pdf file, but it looks OK. Tried the same file is wvPDF, and it produced
a 400k file with no images that doesn't look too good.

If you know of a polished package that does the same thing let me know,
I was more or less doing it myself for a project. Any other comments,
questions, ideas, flames?


SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug