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?

  • 3
    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 '12 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 '12 at 22:39
  • 3
    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 '12 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 '12 at 23:18
  • This is just an UI convention, each program can in principle do what they wish when "Print to file" is selected. – vonbrand Jan 15 '13 at 15:18

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.

lpr -P "Print_to_PDF" file_to_print

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

  • mmm, -P "Print_to_PDF" gives me this error "lpr: The printer or class does not exist." – Aubrey Jan 4 '17 at 16:08

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.