How to create PDF over LAN into your inbox describes how to let users on your LAN print to a LAN PDF printer and have their PDF files delivered right into their inbox in an e-mail containing the PDF as attachement, the date and time of printing, the number of pages printed and the name of the printjob.

howto


Author : Geert Jansen
Sources : Based on PDF on LAN contrib by C. Jensen : http://mirror.contribs.org/smeserver/contribs/cjensen/mitel/beta/pdf-over-lan-sme_5.6-ONLY
Tested on SME version 5.6 and 6.0.1-01 GPL
Updated : 18 Apr 2005
License : GPL


Frustrated by failing to get PDF printing via CUPS working in our LAN I got back to the PDF on LAN contrib by C. Jensen (see above). This contrib installs a network PDF Printer that stores the generated PDF files in an I-bay. Allthough listed as a beta contrib for SME version 5.6 only, it works like a charm on SME 6.0.1-01. Well technically that is. All PDF's created by the PDF printer have to be collected from an I-Bay named pdfdrop. The HTML directory of this I-Bay holds all the PDF's created for all users alike. Users on our LAN were complaining about having to locate their PDF file(s) between everyone's PDF's in the ibay. I therefore modified the PDF printer and the script that controls the creation of the PDF in such way that the generated PDF is no longer stored on a network share but instead gets send as an attachement in an e-mail contaning the date and time of printing, the number of pages printed and the name of the printjob. Users are very happy now ...

Here's what needs to be done:


1) Install the PDF to LAN contrib by C. Jensen if you not allready have done so before ...


This will give you a network PDF printer named PDF.
The printer is set up in /etc/smb.conf by ways of a custom template fragment: /etc/e-smith/templates-custom/etc/smb.conf/91pdf. Settings in this fragment control the way a printjob is handled by the PDF printer.
Creation of the PDF files as output for the PDF printer's printjobs is controlled by the script: /usr/bin/printpdf.
To be able to mail the PDF output of a printjob from the PDF printer, both these files need some tweaking.
The PDF printer must be modified so it sends extra information about the user, number of pages and the name of the printjob to the printpdf script. And the printpdf script needs to be told how to put this printjob information into an e-mail, attach the PDF and send it to the user that started the printjob.


2) Modify the samba template fragment for the PDF printer ...


1. Edit /etc/e-smith/templates-custom/etc/smb.conf/91pdf.
The printcommand needs to contain three additional arguments:

Add these three arguments to the line: print command = /usr/bin/printpdf %s in the 91pdf template fragment so it reads:

[pdf]
path = /tmp
printable = yes
guest ok = yes
print command = /usr/bin/printpdf %s %u %c '%J'

; There is no need to support listing or removing print jobs,
; since the server begins to process them as soon as they arrive.
; So, we set the lpq (list queued jobs) and lprm (remove jobs in queue)
; commands to be empty.
lpq command =
lprm command =

2. Save the template fragment and expand the smb config file: /sbin/e-smith/expand-template /etc/etc/smb.conf
3. Reload Samba: service smb reload


3) Template and then modify the file /usr/bin/printpdf

1. Create the directories /etc/e-smith/templates/usr/bin and /etc/e-smith/templates-custom/usr/bin/:

mkdir -p /etc/e-smith/templates/usr/bin
mkdir -p /etc/e-smith/templates-custom/usr/bin

2. Copy the file /usr/bin/printpdf into these directories. This way you can allways revert back to the original file.

3. Edit the custom template /etc/e-smith/templates-custom/usr/bin/printpdf

Delete all code after the line: OUTDIR=/home/e-smith/files/ibays/pdfdrop/files
And replace the code with the following code so it reads:

OUTDIR=/home/e-smith/files/ibays/pdfdrop/files
ps2pdf13 $1 $OUTDIR/$2$DATE.temp
mv $OUTDIR/$2$DATE.temp $OUTDIR/$2_$DATE.pdf

# Store users e-mailadress in variable named 'TO'
# Username is received via the second argument of the modified printcommand of the PDF printer
# append @yourdomain.com to create a valid email address

TO=$2@yourdomain.com

# Create a temp file to hold the mailbody
# Available variables:

# $1    - Name of spoolfile
# $2    - User name
# $3    - Number of pages
# $4    - Printjob name
# $DATE - Timestamp from original script

T=$OUTDIR/$2$DATE.txt

echo "" > $T
echo "************************** PDF CREATED FOR YOU ****************************" >> $T
echo "Hello $2," >> $T
echo "Here's your requested PDF file." >> $T
echo "***************************************************************************" >> $T
echo "Job Name     : $4" >> $T
echo "Submitted at : $DATE" >> $T
echo "# Pages      : $3" >> $T
echo "Attached as  : $2_$DATE.pdf." >> $T
echo "***************************************************************************" >> $T

# Use mutt to generate an email containing the text above and has the PDF attached

mutt -a $OUTDIR/$2_$DATE.pdf  -i $T -s "PDF:$DATE:$4" $TO

# No need to save the PDF and text file $T

rm $1
rm $T
rm $OUTDIR/$2_$DATE.pdf



Save the changes to the template and expand it:

/sbin/e-smith/expand-template /usr/bin/printpdf

Now for the nice part of this howto: Print something to the PDF printer and watch your inbox ....

The original printpdf script can be found here: http://ldp.rtin.bz/LDP/LG/issue72/bright.html

Geert