1

I have a Linux PC with CUPS and a printer connected to it. Is it possible to get a PostScript document that CUPS driver generates and sends to the printer when I create a print job?

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
AndrewR
  • 592
  • 2
  • 6
  • 20
  • 1
    If the printer is offline or stopped (or while the request is not completed maybe), you can get hold of the file somewhere under `/var/spool` I think, but it may not be named .ps but arbitrary, check for modification time and first line starting %!PS – Stefan Hegny Feb 10 '17 at 09:13
  • @StefanHegny Thank you! `/var/spool/cups/` contains not only stopped jobs, but also several last jobs (in case user wants to restart it). – AndrewR Feb 10 '17 at 09:33

1 Answers1

3
  1. The comment advising you to stop the print queue and fetch the jobfile from /var/spool/cups/ falls short:

    • What you'll find there is NOT the jobfile as it would be sent to a (PostScript) printer.
    • It is the jobfile in the original shape and format as it was received by CUPS.

     
    Now the received file MAY already be in PostScript format (if the printing application was, say, Firefox). But it can also be any format accepted by CUPS (text, image, PDF or "raw" input formats). Even if it is PostScript, CUPS will still somewhat process it before it sends it off to the print device. The amount of processing depends on the definite job options requested by the user.

  2. To really intercept the exact same bytestream that would be sent to the printer by a CUPS queue can be a bit more work (as my StackOverflow answer linked shows).

    However, you may be lucky by trying the following steps:

    • Put FileDevice Yes into your cupsd.conf. (Stop your CUPS service and restart it after you edited the configuration file.)
    • Take note of your current "backend" URI for the print queue you want to intercept by running:

      lpstat -v
      

      (This is only to make sure that you can later restore it to the same working state as before.)

    • Modify your existing CUPS queue by running

      lpadmin -p printername -v file:/var/spool/cups/tmp/ps-test.ps
      
    • Now your queue is disconnected from its real device URI and "connected" to the "file" device. It will now store all processed print jobs in the location /var/spool/cups/tmp/ps-test.ps. (You may need root privileges to scrap it off or read it there.)

     
    You'll be more "unlucky" if your CUPS version is rather recent. There the FileDevice configuration parameter has been removed due to security considerations.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345