7.6. Creating a PDF Printer
The flexibility of Samba's printing hooks has inspired administrators to configure printer shares that do more than just print. One of the more common examples is a printer that converts a document to PDF and then mails the resulting file back to the user. This process is actually easier than it might sound at first. It does, however, require an external tool, such as Ghostscript's ps2pdf command, to convert the spooled job to PDF.
The first step in creating a PDF printer is to create the share in smb.conf. The caveat is that a printing type other than CUPS must be specified. Remember that the printing commands are ignored when Samba has CUPS printing support enabled. So for our example, we will use BSD printing, even though our server may not be running an lpd daemon:
[pdfgen] print ok = yes printing = bsd comment = PDF Generator (requires postscript input) path = /var/spool/samba
Next we need a script that will handle the work of converting the PostScript file to PDF and mailing it back to the user. Error checking and general paranoia has been removed from the script in order to keep it short for example purposes:
#!/bin/sh ## /etc/samba/pdfgen.sh <ps_file> <user> <document_name> PSFILE=$1 USERNAME=$2 JOBNAME=$3 PDFFILE='echo $PSFILE | cut -d. -f1'.pdf /usr/bin/ps2pdf $PSFILE $PDFFILE /usr/bin/mail -s "$JOBNAME PDF conversion" \ -a $PDFFILE $USERNAME < /dev/null
The next step is to set the print command to execute this script. Because we are not dealing with a real printer, we set the lpq command to return an empty list, so as to prevent jobs from being displayed on the client's queue listing window:
print command = /etc/samba/pdfgen.sh %s %u '%J' lpq command = /bin/true
Assuming that the client sends a valid PostScript file, the user should receive a copy of the document in PDF format. That is of course a large assumption, which brings us to a discussion of centrally managing Windows print drivers.