16

The Emacs manual says:

M-x print-buffer

Print hardcopy of current buffer with page headings containing the file name and page number.

M-x lpr-buffer

Print hardcopy of current buffer without page headings.

M-x print-region

Like print-buffer but print only the current region.

M-x lpr-region

Like lpr-buffer but print only the current region.

[...]

To specify the printer to use, set the variable printer-name. The default, nil, specifies the default printer.

How do we specify the printer to use?

For example, a PDF printer, which is not shown in the output of

lpstat -p -d

Thanks.

Tim
  • 4,987
  • 7
  • 31
  • 60
  • You would need to install `cups-pdf` package, then follow the instructions here: https://wiki.archlinux.org/index.php/CUPS#PDF_virtual_printer (there isn't much to do, but be warned it is very likely that your user isn't allowed to print anything at all... CUPS is a fundamentally user-ugly system. So, you would need to log in as root (or find a way to make your user eligible for printer management, and no, it is not enough to be a sudoer). Then you can print just as you intended to. But (as I commented on your other question), PS and then `ps2pdf` will look nicer. – wvxvw Feb 18 '15 at 22:14

2 Answers2

10

If you are on Linux you can install gtklp and set

(setq lpr-command "gtklp")
(setq ps-lpr-command "gtklp")

to give you a graphical print wizard. This doesn't actually give you print-to-file (unless you have a virtual pdf printer set up in CUPS), but it generally allows for easy printing from emacs.

Ista
  • 1,148
  • 8
  • 12
3

The printing happens to the printer name set in the environment variable PRINTER.

For example:

  • I would first set the env var PRINTER to my-printer
  • Then launch emacs in that terminal
  • Then do M-x ps-print-buffer-with-faces
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
  • So you have to restart Emacs to select a different printer? – Supernormal Dec 07 '16 at 19:19
  • Ah, no: doing customize-apropos printer name lets you type in the name of the printer to use. – Supernormal Dec 07 '16 at 19:22
  • @Supernormal `printer-name` works if the user hasn't set the `PRINTER` env variable name, I believe, as per [this](http://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/printing.el?id=6d410fb03c53a892d2cf19238b15c5957ec1a7d8#n1936)... Note that the `PRINTER` env var gets the highest precedence. – Kaushal Modi Dec 07 '16 at 19:29