0
  • OS FreeBSD-12.1
  • CUPS-2.3.3

My goal is to get CUPS to listen for TCP/IP connections on 9100, or any arbitrary ip address and tcp port for that matter, passing the incoming RAW spool file to the cups-pdf filter. After which a cron job or listener process transfers the resulting files to a WebDAV resource for access.

I would like to accomplish the pdf conversion task entirely within CUPS. I have looked at netcat and socat and these may be where I end up. But if it is at all possible to accomplish this with CUPS then I would like to know exactly how one configures a CUPS service to listen on a specific IP address and port; and to route what arrives on that TCP socket to a specific printer.

Is this possible? If so, how is it done?

James B. Byrne
  • 337
  • 1
  • 4
  • 14

1 Answers1

0

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,

James B. Byrne
  • 337
  • 1
  • 4
  • 14