Over the years, I have been asked by several peiple about using the LP service to archive print jobs. Most recently, someone asked how they might go about using an LP queue to create an archive directory of PDF files. The goal was to setup a print queue that they could print to, have the print service generate PDF files, and store them somewhere.
This time, I have decided to write a short description here in my blog for others to hopefully benefit from.
Before we begin, there are a few things that you should know about LP.
- It performs backend job processing using a shell script (interface script) to do final job processing and send it to the printer.
- It runs "slow" filters out of band prior to scheduling the print job to print and "fast" filters are expected to be run by the interface script.
- It will construct a filter chain (of commands) to run to convert from the input format to the print queue's content type
- filter definitions are not configured in the system by default.
- filters and interface scripts run as the submitting user if they originated on the local host and 'lp' if they did not.
So the above request can be broken into two tasks: converting job data to PDF and archiving it.
Converting job data to PDF can be done a few ways, but the easiest way is to define a filter to convert from 'postscript' to 'pdf' and make the print queue's content type 'pdf'. This way, lpsched will create a filter chain, perform the conversion, and queue the job for printing. If it can't perform the conversion, the job will not be accepted.
To define the filter, we need to create a filter definition file and import it into LP:
# cat <<EOF >/etc/lp/fd/ps2pdf.fd Input types: postscript Output types: pdf Printer types: any Printers: any Filter type: slow Command: /usr/bin/ps2pdf14 - - EOF # for i in *.fd ; do ; lpfilter -f `basename $i .fd` -F $i ; done
Next we need to create an interface script that archives the job data. More or less, interface scripts are run by lpsched as follows:
/etc/lp/interfaces/{printer} "{request_id}" "{user_name}" "{title}" "{copies}" "{options_list}" {file_list}...
Our interface script should log the arguments and copy file files in the file_list somewhere. An example can be found here
To define a print queue that uses this script and will cause the pdf filtering to run:
# cp /tmp/archive-interface-script to /usr/lib/lp/model # lpadmin -p test -v /dev/null -Ipdf -Tunknown -m archive # accept test # /usr/bin/enable test
That's it.
One of these days I will have to dig up my old audio alerts package for LP that tells you when the printer runs out of paper or needs attention. (I got tired of walking to the printer only to find that it had been neglected, so I made it annoying enough for people to want to fix it.)






