CUPS - output a copy of all print jobs as PDF

Is it possible to configure CUPS so that each print job is also saved as a PDF?

I've installed and configured cups-pdf, which works fine if I print directly to it from a client.

But what I want to achieve is a copy of all print jobs to be sent to this printer, as well as the normal physical printer.


Solution 1:

Not directly, as your client already generates data compatible with your printer via the driver. In some cases this can be a binary format not easily reversible. But mostly it's Postscript or PCL which you then can try to convert.

You can use the files in /var/spool/cups for this.

Some output with file:

d00566-001: PJL encapsulated PostScript document text
d00575-001: HP Printer Job Language data
d00459-001: PDF document, version 1.7

Now, depending on what printer you have you can use ghostscript to convert the file to a PDF. If it's already a PDF you just rename and open it. You also need to try ghostpcl which can convert PCL data to PDF.

Example:

/opt/ghostpcl-9.53.3-linux-x86_64/gpcl6-9533-linux-x86_64 -sDEVICE=pdfwrite -o /home/out.pdf d00575-001