From owner-ntemacs-users@cs.washington.edu Mon Jul 26 08:47:52 1999 X-VM-v5-Data: ([nil nil nil nil nil nil nil nil nil] [nil "Mon" "26" "July" "1999" "16:33:02" "+0100" "Andrew Innes" "andrewi@harlequin.co.uk" nil "172" "How to print in 20.4 (was Re: 20.4 issues)" "^From:" nil nil "7" nil nil nil nil] nil) Received: from trout.cs.washington.edu (trout.cs.washington.edu [128.95.1.178]) by june.cs.washington.edu (8.8.7+CS/7.2ju) with ESMTP id IAA24214 for ; Mon, 26 Jul 1999 08:47:51 -0700 Received: (majordom@localhost) by trout.cs.washington.edu (8.8.5+CS/7.2trout) id IAA05219 for ntemacs-users-outgoing; Mon, 26 Jul 1999 08:34:18 -0700 (PDT) Received: from june.cs.washington.edu (june.cs.washington.edu [128.95.1.4]) by trout.cs.washington.edu (8.8.5+CS/7.2trout) with ESMTP id IAA05215 for ; Mon, 26 Jul 1999 08:34:16 -0700 (PDT) Received: from holly.cam.harlequin.co.uk (holly.cam.harlequin.co.uk [193.128.4.58]) by june.cs.washington.edu (8.8.7+CS/7.2ju) with ESMTP id IAA23490 for ; Mon, 26 Jul 1999 08:33:59 -0700 Received: from gpo.cam.harlequin.co.uk (gpo.cam.harlequin.co.uk [192.88.238.241]) by holly.cam.harlequin.co.uk (8.8.4/8.8.4) with ESMTP id QAA14247 for ; Mon, 26 Jul 1999 16:33:42 +0100 (BST) Received: from gridlock.cam.harlequin.co.uk (gridlock.cam.harlequin.co.uk [192.88.238.223]) by gpo.cam.harlequin.co.uk (8.8.4/8.8.4) with ESMTP id QAA16249; Mon, 26 Jul 1999 16:33:02 +0100 (BST) Message-Id: <199907261533.QAA16249@gpo.cam.harlequin.co.uk> In-reply-to: <379C142D.492A1628@inf.ethz.ch> (message from Erwin Achermann on Mon, 26 Jul 1999 09:54:22 +0200) References: <379C142D.492A1628@inf.ethz.ch> Precedence: bulk X-FAQ: http://www.cs.washington.edu/homes/voelker/ntemacs.html From: Andrew Innes Sender: owner-ntemacs-users@cs.washington.edu To: ntemacs-users@cs.washington.edu Subject: How to print in 20.4 (was Re: 20.4 issues) Date: Mon, 26 Jul 1999 16:33:02 +0100 (BST) [ I started replying to Erwin's question below, and realised this was expanding into a FAQ answer. I then discovered there are some glitches in the printing support when using external programs that I hadn't really appreciated before. These glitches are something that we should really try to address properly in a later release, but for now I've done my best to describe reasonable work-arounds for use with 20.4. ] On Mon, 26 Jul 1999 09:54:22 +0200, Erwin Achermann said: >2. Printing worked for me on 20.3.1 but now with the same .emacs i get > >Loading lpr... >Loading lpr...done >Spooling with options (page headers are not supported)... >IO error writing c:/PRN: Bad file descriptor > > I know that printing was an issues on this list several times. There >seem to be a bunch of problems to care. I am desperately asking some >kind soul to post some canonical settings for printing. Maybe this will >all add up to a section in the FAQ. (with/without print-nt(version?), >(not) using GS, to a unix-printer, etc.. ) Printing (very) plain text -------------------------- In 20.4, you should start by clearing out ALL printing-related settings from your .emacs, especially packages like print-nt that were written for older releases. If you have a printer physically attached to your computer, then I believe the default settings will very likely work just as they are (assuming you have already configured Windows to support the printer, and can successfully print a test page). So first try loading a small text file (eg. BUGS in the main emacs directory), and then selecting Tools -> Print -> Print Buffer from the menubar. If you don't have a printer physically attached, or it is not attached to the standard parallel printer port (LPT1), then set `printer-name' accordingly: (setq printer-name "LPT2:") ; non-standard port (setq printer-name "//some-server/its-printer") ; network printer Again try Tools -> Print -> Print Buffer from the menubar, to see if it works. For network printers, remember the rule: Emacs will only be able to print to "//some-server/its-printer" if "its-printer" is listed as a shared printer in the output of "net view some-server". Printing formatted text ----------------------- Okay, the first bit covers printing plain text files in a very simple manner (no headers, page numbers, or any kind of formatting at all). If you want something nicer than that, and you probably do, you can either use Tools -> Print -> PostScript Print Buffer (provided you have a PostScript printer, or are happy to set up GhostScript -- see below), or you will need to use an external program to provide nicer formatting. The simplest situation is that you have a PostScript printer, and it is accessible via the `printer-name' setting above. In this case, invoking the PostScript Print Buffer function should just work. There are a bunch of `ps-print-*' and `ps-spool-*' variables which can be customized to tweak the output in various ways. You can set `ps-printer-name' explicitly if `printer-name' needs to be set to something else. However, if none of the above solutions is suitable for you, either because you want nice formatting, don't have a PostScript printer, or can't access a network printer because it doesn't have a Windows share name, then you will need to setup Emacs to use an external program. The procedure is pretty much the same whichever program you use. Using an external formatting program ------------------------------------ The basic procedure is to set `lpr-command' to the name of the external program, and `lpr-switches' to something appropriate for that program to tell it to print a text file. With two exceptions (NT's "print.exe" and Netware's "nprint.exe", which both use only printer-name), the external program specified by `lpr-command' will be invoked with the command line arguments specified by `lpr-switches', followed by "-P" and the value of `printer-name' (as one argument) unless you set printer-name to nil, followed by the name of a temporary file containing the text to be printed. So this is how it _should_ work (but keep reading!!): ;; Use Notepad to print plain text files to the default Windows printer (setq lpr-command "notepad") (setq lpr-switches '("/p")) (setq printer-name nil) Uhh - Houston, we still can't print... -------------------------------------- However this isn't the whole story, and I've just realised that a problem arises because the standard Print Buffer menu function asks Emacs to print page headers, and this really assumes you are running on Unix and can use the normal utilities for formatting and printing. On Unix, page headers are generated either by passing an extra switch to the lpr program (defined by `lpr-headers-switches') OR by invoking an external program (defined by `lpr-page-header-program' defaulting to "pr") with its own set of switches. Unfortunately, there isn't a standard Windows utility equivalent to "pr", and notepad doesn't support any command line switches apart from /P. Okay, something that actually works ----------------------------------- If you are willing to use `M-x lpr-buffer' instead of Print Buffer, then the above settings do work since Emacs then doesn't attempt to generate page headers. You can even change the Print menu functions to hide this, like so: (define-key menu-bar-print-menu [print-region] '("Print Region" . lpr-region)) (define-key menu-bar-print-menu [print-buffer] '("Print Buffer" . lpr-buffer)) BTW, although I've used notepad as an example here, you might not want to use it in practice, partly because of the file size limitation on Windows 9x, and because the page header includes the file name, which is a temporary name chosen at random that looks like gibberish (eg. "EP217Mgm"). A third-party program like pfe32 might work better, since it might have options to surpress the filename or possibly to allow specifying a string to use instead. In the longer term, it would be better to give the temp file a name which matches the original, or is otherwise more reasonable. Another (rather kludgy) way to work around the problem with Emacs trying to print page headers is as follows: ;; Use Notepad to print plain text files to the default Windows printer (setq lpr-command "notepad") (setq lpr-headers-switches '("/p")) ; \ mis-use these (setq lpr-switches nil) ; / two variables (setq printer-name nil) Using GhostScript ----------------- To use GhostScript as a substitute for a PostScript printer, so that you can use the PostScript Print Buffer menu commands to get better control over formatting, the following settings are needed (I've tested this with the 5.10 version of GhostScript for Windows - adjust as appropriate): (setenv "GS_LIB" "c:\\gstools\\gs5.10;c:\\gstools\\gs5.10\\fonts") (setq ps-lpr-command "c:/gstools/gs5.10/gswin32c") (setq ps-lpr-switches '("-q" "-dNOPAUSE" "-dBATCH" "-sDEVICE=mswinprn")) (setq ps-printer-name t) Reportedly, for GS 5.50, the following is needed: (setenv "GS_LIB" "c:\\gstools\\gs5.50;c:\\gstools\\gs5.50\\fonts") (setq ps-lpr-command "c:/gstools/gs5.50/gswin32c") (setq ps-lpr-switches '("-q" "-dNOPAUSE" "-dBATCH" "-sDEVICE=mswinpr2")) (setq ps-printer-name t) Note that each argument to ps-lpr-switches needs its own set of quotes; if you group them together in one string, you will not get the semantics that you want. This brings up the standard printer selection dialog, allowing you to choose any printer known to Windows as the destination for your print-out. Note that GhostScript will usually have to generate a complete bitmap for each page, which can be quite large and can therefore be quite slow. Apparently, it is possible to install GhostScript in such a way that it creates "virtual" PostScript printers known to Windows, which redirect the jobs through GhostScript in the background to a real non-PostScript printer. I haven't tried that myself, and I've heard that other people have been unable to make it work with Emacs. At least the method above has actually been tested on my machine (to some degree). AndrewI