When you select "Print to File" in a Gnome print dialog (not cups-pdf):


... what is the actual command that gets executed? (I'm interested in the postscript variant, as on the image)

On the other hand - maybe there isn't a command call; maybe it is gtk_print_operation_set_export_filename from The new Gtk+ Printing API?

In any case - is there a way for me to utilize this particular code from the command line (not pdf2ps and the like)? Say, by using lpr to "print to file" to a postscript file - as if I was using the dialog above?

  • 4
    AFAIK, this is a feature of the subsystem used by some GNOME and GTK+ applications to print stuff (some of these use Cairo). lpr interacts with cups directly, the print to file option completely bypasses the printing server. it probably doesn't call a command, it just invokes the cairo renderering function in a different way so it generates pdf, postscript or svg output to a file.
    – njsg
    Jun 7, 2012 at 21:27
  • Ah, so its the cairo backend there! Any ideas if a comparable command line is available, that can invoke this rendering function in the same way as the print dialog does? Many thanks for the comment, @njsg - cheers!
    – sdaau
    Jun 7, 2012 at 22:39
  • 4
    There may be some cairo command line tool (I really don't know), but I guess it's a bit tricky, as many applications use cairo to print their own documents, and that application is the one which is able to understand the file format. Cairo won't be able to read random file formats. The closest you can get is to check if the program with the dialog has some commandline option to print a file without opening the GUI.
    – njsg
    Jun 7, 2012 at 23:15
  • Thanks for explaining that @njsg - the above screenshot was taken from the evince print dialog; unfortunately, I cannot see any command line switches by evince that would do something like this.. Cheers!
    – sdaau
    Jun 7, 2012 at 23:18
  • 2
    It's called GtkPrintUnixDialog. If you want to implement your own tool that launches that dialog here's an example in pygobject. I'm posting this as a comment because as far as I know there is no command that does what you want (so there's no answer to your question). The print dialog runs a GtkPrintJob (see documentation) which may use a cairo+postscript backend to get the surface and print the document. Oct 30, 2016 at 17:51

5 Answers 5


You could use the cups-pdf package as a solution independent from gnome. After installing the package, add the PDF printer using the cups webinterface at http://localhost:631 as described here ('General' as printer manufacturer, CUPS-PDF as driver).

For your convenience, change the output directory with the option Out in /etc/cups/cups-pdf.conf to, like, ${HOME} or whatever you want. Then do as suggested by @Noam to print to file.

  • In Ubuntu 18.04, the required apt package is printer-driver-cups-pdf. It sets up a printer called "PDF". Then lpr -P PDF file_to_print works. The default location for files is ${HOME}/PDF.
    – Klimaat
    Feb 22, 2021 at 20:13

Print-to-file sends the document not to the printer but to a pdf document.

Same can be done with the cups printing system, which your applications use when they send print commands.

Use the cupsfilter tool. It effectively converts a document. It converts to pdf by default.

$ cupsfilter inputfilename > outputfilename.pdf

As described here.

lpr -P "Print_to_PDF" file_to_print

To get the list of currently configured printers, run lpstat -p -d.

  • 1
    mmm, -P "Print_to_PDF" gives me this error "lpr: The printer or class does not exist."
    – Aubrey
    Jan 4, 2017 at 16:08
  • See also the CUPS documentation for different options of lp and lpr. Jun 23, 2021 at 5:59

You can also use lp printing command to print a file to the default (or only) printer on the system:

lp filename

or to a specific printer

lp -d printer filename

In case anyone else is late to the party like me it seems the following does the trick at reproducing "print to file"

pdftocairo input.pdf output.pdf -pdf

I discovered this by opening a pdf with Evince in Gnome and then printing to file. It seems cairo graphics is used in the background when printing to a file this way: running pdfinfo on the resulting file reveals

Producer: cairo 1.16.0 (https://cairographics.org)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .