I was unable to use CUPS for this specific problem. I ended up using a combination of socat
and gpcl6
.
export HPNP=4179 ; socat TCP4-LISTEN:4179,bind=192.168.216.179,fork,reuseaddr,su=hp3000 SYSTEM:'gpcl6 -dNOSAFE -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=/var/spool/hp3000/np${HPNP}/HP3000-RPT-$(date -Iseconds).pdf -' &
socat
takes the connection and passes it to gpcl6
via stdin ( - ). gpcl6
uses the pdfwrite
printer to process the output file. The pdf output file is named with a source tag (external) plus a dynamic timestamp.
On the legacy host define a network printer to spool to 192.168.216.179:9100. Send the spool files to convert to pdf to that printer.
Each print job creates its own pdf. The timestamp prevents filename collisions. The gpcl6 -dNOSAFE option is required to allow gpcl6 to write to a file.
I further extended this to provide for PCL3 form overlays and multiple pdfs per spool file. An exmple of this is:
export HPNP=4178 ; socat TCP4-LISTEN:4178,bind=192.168.216.179,fork,reuseaddr,su=hp3000 SYSTEM:'sed -r "1s/^.{42}//" | cat /var/spool/hp3000/forms/hll_inv_ljiii_85.ovl - | gpcl6 -dNOSAFE -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=/var/spool/hp3000/np${HPNP}/HP3000-INV-$(date -Iseconds)-%03u.pdf -' &
In this example the PCL3 overlay file is picked up by cat
which prepends it to the spooled data stream and passes that to gpcl6
. The -sOutputFile
option of gpcl6
contains a printf
format string (%03u) which triggers gpcl6
to break the incoming spool file into individual pdf files at each page break. Depending upon the spool file there may one or two artifacts, a blank sheet or a blank copy of the overlay form, created in addition to the actual documents.
The sed
command strips off leading PCL commands created by the generating host,