[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

AH.5 Printing and MS-DOS

Printing commands, such as lpr-buffer (see section AC.18 Hardcopy Output) and ps-print-buffer (see section AC.19 PostScript Hardcopy) can work in MS-DOS and MS-Windows by sending the output to one of the printer ports, if a Posix-style lpr program is unavailable. The same Emacs variables control printing on all systems (see section AC.18 Hardcopy Output), but in some cases they have different default values on MS-DOS and MS-Windows.

If you want to use your local printer, printing on it in the usual DOS manner, then set the Lisp variable lpr-command to "" (its default value) and printer-name to the name of the printer port--for example, "PRN", the usual local printer port (that's the default), or "LPT2", or "COM1" for a serial printer. You can also set printer-name to a file name, in which case "printed" output is actually appended to that file. If you set printer-name to "NUL", printed output is silently discarded (sent to the system null device).

On MS-Windows, when the Windows network software is installed, you can also use a printer shared by another machine by setting printer-name to the UNC share name for that printer--for example, "//joes_pc/hp4si". (It doesn't matter whether you use forward slashes or backslashes here.) To find out the names of shared printers, run the command `net view' at a DOS command prompt to obtain a list of servers, and `net view server-name' to see the names of printers (and directories) shared by that server. Alternatively, click the `Network Neighborhood' icon on your desktop, and look for machines which share their printers via the network.

If the printer doesn't appear in the output of `net view', or if setting printer-name to the UNC share name doesn't produce a hardcopy on that printer, you can use the `net use' command to connect a local print port such as "LPT2" to the networked printer. For example, typing net use LPT2: \\joes_pc\hp4si(18) causes Windows to capture the LPT2 port and redirect the printed material to the printer connected to the machine joes_pc. After this command, setting printer-name to "LPT2" should produce the hardcopy on the networked printer.

With some varieties of Windows network software, you can instruct Windows to capture a specific printer port such as "LPT2", and redirect it to a networked printer via the Control Panel->Printers applet instead of `net use'.

Some printers expect DOS codepage encoding of non-ASCII text, even though they are connected to a Windows machine which uses a different encoding for the same locale. For example, in the Latin-1 locale, DOS uses codepage 850 whereas Windows uses codepage 1252. See section AH.6 International Support on MS-DOS. When you print to such printers from Windows, you can use the C-x RET c (universal-coding-system-argument) command before M-x lpr-buffer; Emacs will then convert the text to the DOS codepage that you specify. For example, C-x RET c cp850-dos RET M-x lpr-region RET will print the region while converting it to the codepage 850 encoding. You may need to create the cpnnn coding system with M-x codepage-setup.

If you set printer-name to a file name, it's best to use an absolute file name. Emacs changes the working directory according to the default directory of the current buffer, so if the file name in printer-name is relative, you will end up with several such files, each one in the directory of the buffer from which the printing was done.

The commands print-buffer and print-region call the pr program, or use special switches to the lpr program, to produce headers on each printed page. MS-DOS and MS-Windows don't normally have these programs, so by default, the variable lpr-headers-switches is set so that the requests to print page headers are silently ignored. Thus, print-buffer and print-region produce the same output as lpr-buffer and lpr-region, respectively. If you do have a suitable pr program (for example, from GNU Textutils), set lpr-headers-switches to nil; Emacs will then call pr to produce the page headers, and print the resulting output as specified by printer-name.

Finally, if you do have an lpr work-alike, you can set the variable lpr-command to "lpr". Then Emacs will use lpr for printing, as on other systems. (If the name of the program isn't lpr, set lpr-command to specify where to find it.) The variable lpr-switches has its standard meaning when lpr-command is not "". If the variable printer-name has a string value, it is used as the value for the -P option to lpr, as on Unix.

A parallel set of variables, ps-lpr-command, ps-lpr-switches, and ps-printer-name (see section AC.20 Variables for PostScript Hardcopy), defines how PostScript files should be printed. These variables are used in the same way as the corresponding variables described above for non-PostScript printing. Thus, the value of ps-printer-name is used as the name of the device (or file) to which PostScript output is sent, just as printer-name is used for non-PostScript printing. (There are two distinct sets of variables in case you have two printers attached to two different ports, and only one of them is a PostScript printer.)

The default value of the variable ps-lpr-command is "", which causes PostScript output to be sent to the printer port specified by ps-printer-name, but ps-lpr-command can also be set to the name of a program which will accept PostScript files. Thus, if you have a non-PostScript printer, you can set this variable to the name of a PostScript interpreter program (such as Ghostscript). Any switches that need to be passed to the interpreter program are specified using ps-lpr-switches. (If the value of ps-printer-name is a string, it will be added to the list of switches as the value for the -P option. This is probably only useful if you are using lpr, so when using an interpreter typically you would set ps-printer-name to something other than a string so it is ignored.)

For example, to use Ghostscript for printing on an Epson printer connected to the `LPT2' port, put this in your `_emacs' file:

 
(setq ps-printer-name t)  ; Ghostscript doesn't understand -P
(setq ps-lpr-command "c:/gs/gs386")
(setq ps-lpr-switches '("-q" "-dNOPAUSE"
			"-sDEVICE=epson"
			"-r240x72"
			"-sOutputFile=LPT2"
			"-Ic:/gs"))

(This assumes that Ghostscript is installed in the `"c:/gs"' directory.)

For backwards compatibility, the value of dos-printer (dos-ps-printer), if it has a value, overrides the value of printer-name (ps-printer-name), on MS-DOS and MS-Windows only.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on April 2, 2002 using texi2html