On Linux, you can use the cups-pdf package to implement a virtual PDF printer. What is a PDF printer? This is a virtual device that is added to the system as a regular printer and when a document is sent for printing, it generates a PDF file from it.
Verify that the Common UNIX Printing System (CUPS) printing subsystem is installed on your Linux host. Check if the computer is listening on port TCP/631 and that the cups service is up and running:
$ sudo netstat -tupnl
$ sudo systemctl status cups
You can now install the cups-pdf package:
- On Ubuntu/Debian:
$ sudo apt install cups-pdf
- On RHEL/Fedora/CentOS:
# yum install cups-pdf
Restart the cups print service:
$ sudo service cups restart
List installed printers and show which printer is assigned as the default device:
$ sudo lpstat -p -d
CUPS-PDF (Virtual PDF Printer)
system default destination: PDF
device for PDF: cups-pdf:/
If the printer is disabled, you can enable it:
$ cupsenable CUPS-PDF
You can manually create a new virtual PDF printer in CUPS with the command:
$ sudo lpadmin -p cups-pdf -v cups-pdf:/ -E -P /usr/share/ppd/cups-pdf/CUPS-PDF_opt.ppd
If a virtual printer appears in the list, you can send any documents to it and save the result as a PDF file. By default, files in the name-job_N.pdf format are saved to the user’s ~/PDF directory.
You can change the directory path for the PDF files in the /etc/cups/cups-pdf.conf configuration file (
You can manage the virtual PDF printer’s settings and print queue through the CUPS web interface.
In your browser, navigate to the
Select the Generic CUPS-PDF Printer (w/ options)
Here you can change the print settings (page size, output resolution), share the printer, clear the print queue, etc.
Driver: Generic CUPS-PDF Printer (w/ options) (color)
Defaults: job-sheets=none, none media=iso_a4_210x297mm sides=one-sided
You can print to PDF from any application or directly from the Linux console. For example, to save the console output to a PDF file, simply pipe it to lpr (the default printer is used to print).
$ cat /etc/cups/cups-pdf.conf | lpr
Or, you can send the text file to be printed to PDF in the following way:
$ lp -d PDF testfile.txt