The topic of this page is printing from within Emacs. This includes printing Emacs buffers and regions. It includes printing using different operating systems, color printing, etc.
Emacs comes with libraries printing.el
, lpr.el
, and ps-print.el
, but they are not preloaded.
lpr.el
and ps-print.el
(PsPrintPackage) provide printing commands for use with text and PostScript printers. This includes color printing and printing using the highlighting (faces) you see in Emacs itself.printing.el
is an extension of library ps-print.el
that provides a complete set of highly customizable menus and commands for all kinds of printing from within Emacs. It lets you easily print using different printers and different operating systems (e.g. Windows, Unix, Linux). It lets you preview printing with ghostview. Library printing.el
(PrintingPackage) is available from ViniciusJoseLatorre. (DrewAdams recommends library printing.el
.)For those who wish to print on a local printer when running emacs through an ANSI terminal or alike (eg PuTTY), there is ansi-lpr (http://lists.gnu.org/archive/html/gnu-emacs-sources/2005-03/msg00007.html) (a library whose code length is less than its licence!). It allows users to print using the familiar commands (‘print-buffer’
or ‘print-region’
) provided by lpr.el.
N.B. When downloading the library, make sure the control characters are still there – Matthias.
A way to easily print documents on Microsoft Windows is to add the following forms to your Emacs InitFile:
(setenv "GS_LIB" "e:/tools/GSTools/gs8.14/gs8.14/lib;e:/tools/GSTools/gs8.14/fonts") (setq ps-lpr-command "e:/tools/GSTools/gs8.14/gs8.14/bin/gswin32c.exe") (setq ps-lpr-switches '("-q" "-dNOPAUSE" "-dBATCH" "-sDEVICE=mswinpr2")) (setq ps-printer-name t)
You have to change the paths to reflect the actual directories on your system. The setenv
form might not be necessary if GS_LIB
is already set in the underlying environment.
This requires Ghostscript, but no extra Emacs library. You can print as usual with the “ps-print” commands. A pop-up will ask for the printer to send the output to.
Unfortunately, you should read the section Adware toolbar controversy on the Wikipedia page before installing it. :sucks:
If you decide to install it anyway, PDFCreator is a version of ghostscript & ghostview that acts like a windows printer driver. It allows you to create PDF’s from any windows application that will let you print.
You can tune the PDFCreator to do all sorts of things, I have it set to autosave the PDF and open it in Acrobat. Most Windows Emacsians have cygwin installed, this uses the cygwin version of lpr. To set Emacs up to use it add the following to your InitFile:
(setenv "PRINTER" "PDFCreator") (cond ((eq system-type 'windows-nt) (setq ps-printer-name "PDFCreator") (setq ps-printer-name-option "-d") (setq ps-lpr-command "/bin/lpr"))) ; if you're using the Emacs in Cygwin ;(setq ps-lpr-command "c:/cygwin/bin/lpr.exe"))) ; if you're using the native Windows build of Emacs
To test use ps-print-buffer. – TimOCallaghan
See also: PrintingPackage and PsPrintPackage.
See PrintCommandQuotes for a work-around.
See PrintUsingWord.
Create /usr/local/bin/print_preview
:
#!/bin/sh PREVIEW_FILE=$(mktemp --suffix=.ps) cat >"$PREVIEW_FILE" && evince "$PREVIEW_FILE" || \ notify-send 'Print preview failed' --urgency=critical \ --expire-time=2000 rm "$PREVIEW_FILE"
Configure Emacs:
(setq ps-lpr-command "print_preview")