Create a .pdf copy while printing document


Are there any suggestion how I can setup my cups server, if I print a document on a physical printer, save a pdf copy of the file somewhere on my system?
Thank you in advance!

1 Like

If I can make a suggestion, please edit this topic to say “while printing document” instead of “of printed document”… otherwise it sounds like you want to scan something you’ve already printed :slight_smile:


Hello @thewanderer ,
Welcome to :fedora: !
So yeah, if you have the file open in whatever app that you are printing from the printer dialogue should have the option to print to file where you can select PDF as the format (or PS, etc…) like this from Gnome Text Editor …

Happy printing!
Or … from the terminal, if you have pandoc installed it can convert many document formats from the command line without the need to open it in an editor and get the print dialogue.

Hello @jakfrost !
Thank you!
I know how I can print to PDF, I’d like to save a PDF copy of the current printing job automatically.

So you don’t want the document in PDF just the print job in PDF, am I correct?
[edit] : So that would likely be through the CUPS api, but since it is predominantly browser based, perhaps they have some endpoints accessible for you to exploit for this info.

What I want is to print a physical copy of the document, and save a copy of the file what I have printed. For example, I open a document from the internet, I print it out but I don’t save it, CUPS create a copy and save it for me to /tmp/cups-saves or /var/spool/cups/cups-saves or somewhere :slight_smile:
So I want to save everything what I printing.

Sure okay, but you would likely still need to trigger the CUPS package to save the doc in the first place, which brings me back to the CUPS api (if such exists, I haven’t looked for it). The interface for management of printers is now a browser based app from CUPS, so maybe they already have endpoints (I’m thinking RESTful here) that you could query and use for triggering saving the doc. Really though, you could (and may have to) also write a script to do this I would think. There may be a third party readily available solution that would run on Fedora Linux, I am not aware of anything like that though, so you would need to search for it.


I do not think there is a possibility to do it with Fedora supported software. I stumbled onto a Python script tea4cups, which is a Cups backend hooking before the real backend. This seems to work, using a hook “cat $TEADATAFILE | lpr -PCups_PDF” making a copy on a Cups_PDF printer. The original printer should go to URI tea4cups://URIoriginal://
The script should be modified to call python2, its from 2006 but it looks still working. I can’t find alternatives except programming a similar backend myself. Third-party software, so use it on your own risk. Copies are placed by the cups-PDF printer in /root/Desktop.

Added: it looks like the rule in /etc/cups/tea4cups.conf:

posthook_0: cat $TEADATAFILE >"/home/hj/prints/${TEATITLE}-${TEAJOBID}.ps"

works, at that level, the print is already postscript.
Only the permissions have to be changed afterwards, and conversion into PDF
I do not know the lifetime of $TEADATAFILE, a script copying the file to a temp location, followed by ps2pdf and changing user permissions is the next step. But it works.

Addition: Tested with Fedoraś Cups-PDF printer. If you have a PCL type of printer, you may have to do it the other way around: print to Cups-PDF and duplicate the print job with “lpr” of the Postscript intermediate to the PCL printer.


Thank you for your replies!
I’ll check tea4cups, and give you feedback, but now I can start somewhere :slight_smile:

There is a second possibility with Fedora software: You need the packages inotify-tools and cups-pdf. Install a cups-pdf printer with options so you can set the resolution to prevent quality loss. Define a folder where the printer stores the PDF’s. Print to the PDF printer instead of the normal printer. A little script monitors the folder and as soon the PDF is ready, it’s printed to the normal printer.
Example script:

#Monitor folder and reprints PDF created.

	while true
		file=`inotifywait -e ATTRIB --format %w/%f $MONIT 2>/dev/null`   
		lpr -P"$DESTPRINTER" "$file" 

If you store a webpage with “Save to PDF” under the name of your choice in this folder, it will be printed automatically. It looks like the Print of Firefox offers CUPS a PDF file, so quality should be the same.

Addition: if you want to try tea4cups: tea4cups is also present in the Debian Linux repositories, and Debian has a wiki page with a lot of examples. The version is adapted for Python3. There is also a github page with the Python3 version. I’ve only tested the old 2006 version adapted to call python2 instead of python.


Thank you @hmmsjan !
Tonight I’ll check both method, but I like the 2nd one more. Tomorrow morning I give you a feedback how is it going.