The Linux Printing HOWTO Grant Taylor, v3.1, 12 February 1996 This is the Linux Printing HOWTO, a collection of information on how to generate, preview, print and fax anything under Linux (and other Unices in general). ______________________________________________________________________ Table of Contents: 1. Intro 1.1. History 1.2. Copyright 2. How to print 3. Where is LPT1? (Or, what does the kernel do?) 4. How it works, basic 5. How to set things up, basic 6. How to obtain an appropriate magic filter 6.1. APS Filter 6.2. Magic-filter 7. Vendor Solutions 7.1. RedHat 2.x 7.2. Other Distributions 8. How to print to a printer over the network 9. How to print to a fax machine. 10. How to generate something worth printing. 10.1. Markup languages 10.2. WYSIWYG 11. Ghostscript. 12. On-screen previewing of printable things. 12.1. PostScript 12.2. TeX dvi ______________________________________________________________________ 1. Intro Since this is a complete rewrite, much information from previous editions has been lost. This is by design, as the previous HOWTOs were so large as to be 60 typeset pages, and had the narrative flow of a dead turtle. If you do not find the answer here, you are encouraged to a) scan the previous version at The PHT Home Page and b) drop me a note saying what ought to be here but isn't. The Printing HOWTO Home Page is a good place to find the latest version; it is also, of course, distributed from SunSite (sunsite.unc.edu) and your friendly local LDP mirror. 1.1. History This is the third generation, which is to say the third complete rewrite, of the Printing HOWTO. The history of the PHT may be chronicled thusly: 1. I wrote the printing-howto in response to too many printing questions in comp.os.linux, and posted it. This predated the HOWTO project by a few months and was thus the first FAQlet called a `howto'. This edition was in plain ascii. 2. After joining the HOWTO project, the Printing-HOWTO was merged with an Lpd FAQ by Brian McCauley ; we continued to co-author the PHT for two years or so. At some point we incorporated the work of Karl Auer . This generation of the PHT was in TeXinfo, and available in PS, HTML, Ascii, and Info. 3. After letting the PHT rot and decay for over a year, and an unsuccessful attempt at getting someone else to maintain it, this rewrite happened. This generation of the PHT is in Linuxdoc-SGML. 1.2. Copyright This document is Copyright (c) 1996 by Grant Taylor. Please copy and distribute it widely, but do not modify the text or omit my name. 2. How to print If you've already got lpd setup to print to your printer, or your system administrator already did so, or your vendor did so for you, then all you need to do is learn how to use the lpr command. The Printing Usage HOWTO covers this, and a few other queue manipulation commands you should probably know. 3. Where is LPT1? (Or, what does the kernel do?) The Linux kernel, assuming you have compiled in or loaded the lp device (the output of cat /proc/devices should include the device lp), provides one or more of /dev/lp0, /dev/lp1, and /dev/lp2. These are NOT assigned dynamically, rather, each corresponds to a specific hardware I/O address. This means that your first printer may be lp0 or lp1 depending on your hardware. Try both ;) One cannot run the plip and lp drivers at the same time. (Is this true port-by-port, or globally on a machine? I think globally, but I haven't tried.) There is a little utility called tunelp floating about with which you, as root, can tune the Linux lp device's interrupt usage, polling rate, and other options. 4. How it works, basic In order to get printing working well, you need to understand how the lpd system works. Lpd stands for Line Printer Daemon, and refers to both the daemon and the whole collection of programs which run print spooling. These are: lpd The spooling daemon. One of these runs to control everything on a machine, AND one is run per printer while the printer is printing. lpr The user spooling command. Lpr contacts lpd and injects a new print job into the spool. lpq Lists the jobs in a print queue. lpc The Lpd system control command. With lpc you can stop, start, reorder, etc, the print queues. lprm lprm will remove a job from the print spool. So how does it fit together? Well, when the computer boots, lpd is run. It scans the file /etc/printcap to learn which printers it will be managing spools for. Each time someone runs lpr, lpr contacts lpd through the named socket /dev/printer, and feeds lpd both the file to print and some information about who is printing and how to print it. Lpd then prints the file on the appropriate printer in turn. The lp system was originally designed when most printers were line printers - that is, people mostly printer plain ascii. As it turns out, only a little extra scripting is needed to make lpd work quite well for today's print jobs, which are often in PostScript, or text, or dvi, or... 5. How to set things up, basic The minimal setup for lpd rsults in a system that can queue files and print them. It will not pay any attention to wether or not your printer will understand them, and will probably not let you produce attractive output. Nevertheless, it is the first step to understanding, so read on! Basically, to add a print queue to lpd, you must add an entry in /etc/printcap, and make the new spool directory under /var/spool/lpd. An entry in /etc/printcap looks like: # LOCAL djet500 lp|dj|deskjet:\ :sd=/var/spool/lpd/dj:\ :mx#0:\ :lp=/dev/lp0:\ :sh: This defines a spool called lp, dj, or deskjet, spooled in the direc- tory /var/spool/lpd/dj, with no per-job maximum size limit, which prints to the device /dev/lp0, and which does not have a banner page (with the name of the person who printed, etc) added to the front of the print job. Go now and read the man page for printcap. The above looks very simple, but there a hitch - unless I send in files a DeskJet 500 can understand, this DeskJet will print strange things. For example, sending an ordinary Unix text file to a deskjet results in literally interpreted newlines, and gets me: This is line one. This is line two. This is line three. ad nauseum. Printing a PostScript file to this spool would get a beu- tiful listing of the PostScript commands, printed out with this "staircase effect", but no useful output. Clearly more is needed, and this is the purpose of filtering. The more observant of you who read the printcap man page might have noticed the spool attributes if and of. Well, if, or the input filter, is just what we need here. If we write a small shell script called filter that adds carriage returns before newlines, the staircasing can be eliminated. So we have to add in an if line to our printcap entry above: lp|dj|deskjet:\ :sd=/var/spool/lpd/dj:\ :mx#0:\ :lp=/dev/lp0:\ :if=/var/spool/lpd/dj/filter:\ :sh: A simple filter script might be: #!perl while(){printf "$_\r";}; If we were to do the above, we'd have a spool to which we could print regular Unix text files and get meaningful results. (Yes, there are four million better ways to write this filter, but few so illustra- tive. You are encouraged to do this more efficiently.) The only remaining problem is that printing plain text is really not to hot - surely it would be better to be able to print PostScript and other formatted or graphic types of output. Well, yes, it would, and it's easy to do. The method is simply an extention of the above linefeed-fixing filter. If you write a filter than can accept arbitrary file types as input and produce DeskJet-kosher output for each case, then you've got a clever print spooler indeed! Such a filter is called a magic filter. Don't bother writing one yourself unless you print strange things - there are a good many written for you already on the net. 6. How to obtain an appropriate magic filter 6.1. APS Filter One of the nicest magic filter packages is aps filter, by Andreas Klemm. The Linux Software Map entry goes something like this: Begin3 Title: apsfilter Version: 4.9.1 Entered-date: Montag, 10. Juli 1995, 21:22:35 Uhr MET DST Description: magicfilter for lpd with auto filetype detection Keywords: lpd magicfilter aps apsfilter Author: andreas@knobel.GUN.de (Andreas Klemm) Maintained-by: sledge@hammer.oche.de (Thomas Bueschgens) andreas@knobel.GUN.de (Andreas Klemm) Primary-site: sunsite.unc.edu /pub/Linux/system/Printing/ 211KB aps-491.tgz Original-site: ftp-i2.informatik.rwth-aachen.de /pub/Linux/pak/APSfilter/aps-491.tgz Platforms: C-Compiler, gs Postscript emulator, pbmutils Copying-policy: GPL End APS filter installs as an if filter for a print queue, and will trans- late from many common file types into your printer's command set. It understands, for example, text, PostScript, dvi, gif, and others. 6.2. Magic-filter The magic-filter package, written by B.A.McCawley, works much the same way as does APSfilter, but since it is written in bash, it might be more easy to customize. The LSM entry: Version: 0.4 Description: Bash scripts to simplify the task of configuring lpd to auto-detect file types using /etc/magic. (As advertised in the printing-HOWTO). This package uses existing filters so it only prints file types for which one already has filters (or compressed versions thereof). Alterative magic filter approches are described in the printing-HOWTO. Keywords: lpd, /etc/magic, printing, filter Author: B.A.McCauley@bham.ac.uk (Brian McCauley) Maintained-by: B.A.McCauley@bham.ac.uk Primary-site: tsx-11.mit.edu pub/linux/sources/usr.bin magic-filter-0.4.tar.gz 5709 Copying-policy: GNU GPL 7. Vendor Solutions This section is, by definition, incomplete. Feel free to send in details of your favourite distribution. 7.1. RedHat 2.x RedHat has a GUI printer administration tool which can add remote printers and printers on local devices. It lets you choose a ghostscript-supported printer type and Unix device file to print to, then installs a print queue in /etc/printcap and writes a short PostScript-and-ascii magic filter based around gs and nenscript. This solution works fairly well, and is trivial to setup for common cases. 7.2. Other Distributions Please send me info on what other distributions do. 8. How to print to a printer over the network One of the features of lpd is that it supports printing over the network to printers physically connected to a different machine. To allow remote machines to print to your printer, you must list the machines in /etc/hosts.equiv or /etc/hosts.lpd. (Note that hosts.equiv has a host of other effects; be sure you know what you are doing if you list any machine there). You can allow only certain users on the other machines to print to your printer by usign the rs attribute; read the lpd man page for information on this. To print to another machine, you make an /etc/printcap entry like this: # REMOTE djet500 lp|dj|deskjet:\ :sd=/var/spool/lpd/dj:\ :rm=machine.out.there.com:\ :rp=printername:\ :lp=/dev/null:\ :sh: Note that there is still a spool directory on the local machine man- aged by lpd. If the remote machine is busy or offline, print jobs from the local machine wait in the spool area until they can be sent. 9. How to print to a fax machine. There are a number of fax programs out there that will let you fax and receive documents. One of the most complex is Sam Leffler's HylaFax, available from ftp.sgi.com. It supports all sorts of things from multiple modems to broadcasting. Also available, and a better choice for most Linux boxen, is efax, a simple program which sends faxes. The getty program mgetty can receive faxes (and even do voicemail on some modems!). 10. How to generate something worth printing. Here we get into a real rat's-nest of software. Basically, Linux can run four types of binaries with varying degrees of success: Linux, iBCS, Win16 (with dosemu and, someday, with Wine), and Mac/68k (with Executor). I'll just discuss native Linux and common Unix software, except to say that WordPerfect for SCO, and quite probably other commercial word processing software, runs fine under Linux's iBCS emulation. For Linux itself, choices are mostly limited to those available for Unix in general: 10.1. Markup languages Most markup languages are more suitable for large or repetative projects, where you want the computer to control the layout of the text to make things uniform. Trying to make a pretty sign in a markup language would probably hurt... nroff This was one of the first Unix markup languages. Man pages are the most common examples of things formatted in *roff macros; many people swear by them, but nroff has, to me at least, a more arcane syntax than needed, and probably makes a poor choice for new works. It is worth knowing, though, that you can typeset a man page directly into postscript with groff. Most man commands will do this for you with man -t foo | lpr. TeX TeX, and the macro package LaTeX, are one of the most widely used markup languages on Unix. Technical works are frequently written in LaTeX because it greatly simplifies the layout issues and is still one of the few text processing systems to support mathematics both completely and well. TeX's output format is dvi, and is converted to PostScript or Hewlett Packard's PCL with dvips or dvilj. SGML There is at least one free sgml parser available for Unix and Linux; it forms the basis of Linuxdoc-SGML's homegrown document system. It can support other DTD'S, as well. 10.2. WYSIWYG There is a general shortage of WYSIWYG document text processing software. Feel free to write some, and do let me know of anything I've omitted here. Lyrix Lyrix is a front-end to LaTeX which looks very promising. The Andrew User Interface System AUIS includes ez, a WYSIWYG-style editor with most basic word processor features, HTML capabilities, and full MIME email and newsgroup support. 11. Ghostscript. Ghostscript is an incredibly significant program for Linux printing. Most printing software under Unix generates PostScript, which is typically a $100-300 option on a printer. Ghostscript, however, is free, and will generate the language of your printer from PostScript. When tied in with your lpd input filter, it gives you a virtual PostScript printer and simplifies life immensely. Ghostscript is available in two forms. The commercial version of Ghostscript, called Aladdin Ghostscript, may be used freely for personal use but may not be distributed by commercial Linux distributions. It is generally a year or so ahead of the free Ghostscript; at the moment, for example, it supports Adobe Acrobat's Portable Document Format, while the older Ghostscripts do not. The free version of Ghostscript is GNU Ghostscript, and is simply an aged version of Aladdin ghostscript kindly given to GNU. (Kudos to Aladdin for this arrangement; more software vendors should support free software in this way). Ghostscript's main failing is in its fonts, which are derived from bitmap scans of the characters. Superior, but commercially licensed fonts may be obtained from several places, since Ghostscript can read type 1 Adobe fonts. Adobe distributes useable fonts with their Acrobat PDF reader, or you may use the fonts from Adobe's ATM or a fontpack. Whatever you do with gs, be very sure to run it with the option for disabling file access (-dSAFER). PostScript is a fully functional language, and a bad PostScript program could give you quite a headache. 12. On-screen previewing of printable things. Nearly anything you can print can be viewed on the screen, too. 12.1. PostScript Ghostscript has an X11 driver best used under the management of the PostScript previewer Ghostview. The latest versions of these programs should be able to view PDF files, as well. 12.2. TeX dvi TeX DeVice Independant files may be previewed under X11 with xdvi. Modern versions of xdvi call ghostscript to render PostScript specials. A VT100 driver exists as well, but I have forgotten its name.