The Linux Printing Usage HOWTO by Mark Komarinski v1.2.2, 6 February 1998 11.. IInnttrroodduuccttiioonn This document describes how to use the line printer spooling system provided with the Linux operating system. This HOWTO is the supplementary document to the Linux Printing Setup HOWTO, which discusses the installation and setup of the Linux printing system. The material presented in this HOWTO should be equally relevent for all flavors of the BSD operating system in addition to the Linux operating system. 11..11.. LLiinnuuxx PPrriinnttiinngg HHOOWWTTOO HHiissttoorryy Note from Mark Komarinski : I'd like to thank Matt Foster for doing a lot of work in the re-write of this HOWTO. I'm keeping his style, and adding when necessary to keep everything updated. Note from Matt Foster : This version of the Linux Printing HOWTO is a complete rewrite of the one originally written by Grant Taylor and Brian McCauley . I have tried to keep with the coverage of material presented by Grant and Brian's HOWTO, but I have drastically modified the style of presentation and the depth of material covered. I feel that this makes the HOWTO more complete and easier to read. I can only hope that you agree. 11..22.. VVeerrssiioonn HHiissttoorryy v1.2.2 +o Re-indexed, other changes to fit in the new RedHat docs. Thanks Ed! v1.2.1 +o updates, some changes for Dr. Linux publication v1.2 +o Windows Printers +o Changing max size of print files v1.11 +o new maintainter! +o Added lpc info +o Added some info for troubleshooting +o A start on printing graphics files! v1.1 +o revised some of the wording +o developed section on PostScript printing +o attempted to clarify some of the examples 8-) +o fleshed the discussion of the basic Linux printing utilities v1.0 +o initial public release of the Printing Usage HOWTO 11..33.. CCooppyyrriigghhttss aanndd TTrraaddeemmaarrkkss Some names mentioned in this HOWTO are claimed as copyrights and/or trademarks of certain persons and/or companies. These names appear in full or initial caps in this HOWTO. _(_c_) _1_9_9_5 _M_a_t_t _F_o_s_t_e_r _(_m_w_f_@_e_n_g_r_._u_a_r_k_._e_d_u_) _(_c_) _1_9_9_6_-_1_9_9_7 _M_a_r_k _F_. _K_o_m_a_r_i_n_s_k_i _(_m_a_r_k_k_@_a_u_r_a_t_e_k_._c_o_m_) All translations, derivative works, or aggregate works incorporating any Linux HOWTO documents must be covered under this copyright notice. That is, you may not produce a derivative work from a HOWTO and impose additional restrictions on its distribution. Exceptions to these rules may be granted under certain conditions; please contact the Linux HOWTO coordinator at the address given below. In short, we wish to promote dissemination of this information through as many channels as possible. However, we do wish to retain copyright on the HOWTO documents, and would like to be notified of any plans to redistribute the HOWTOs. If you have questions, please contact Tim Bynum, the Linux HOWTO coordinator, at . You may finger this address for phone number and additional contact information. 11..44.. DDoowwnnllooaaddiinngg tthhee LLiinnuuxx PPrriinnttiinngg HHOOWWTTOOss I recommend that if you want to print a copy of this HOWTO that you download the PostScript version. It is formatted in a fashion that is aesthetically appealing and easier to read. You can get the PostScript version from one of the many Linux distribution sites (such as SunSITE ). 11..55.. FFeeeeddbbaacckk Questions, comments, or corrections for this HOWTO may be directed to . 11..66.. AAcckknnoowwlleeddggmmeennttss Thanks go out to all of the people who took the time to read the alpha version of this HOWTO and respond with many helpful comments and suggestions---some of you may see your comments reflected in the version. I'd also like to thank Matt Foster who did the original re-write. 22.. PPrriinnttiinngg UUnnddeerr LLiinnuuxx This section discusses how to print files, examine the print queue, remove jobs from the print queue, format files before printing them, and configure your printing environment. 22..11.. HHiissttoorryy ooff LLiinnuuxx PPrriinnttiinngg The Linux printing system---the _l_p system---is a port of the source code written by the Regents of the University of California for the Berkeley Software Distribution version of the UNIX operating system. 22..22.. PPrriinnttiinngg aa FFiillee UUssiinngg llpprr By far, the most simplistic way to print in the Linux operating system is to send the file to be printed directly to the printing device. One way to do this is to use the _c_a_t command. As the root user, one could do something like # cat thesis.txt > /dev/lp In this case, /dev/lp is a symbolic link to the actual printing device---be it a dot-matrix, laser printer, typesetter, or plotter. (See _l_n(1) for more information on symbolic links.) For the purpose of security, only the root user and users in the same group as the print daemon are able to write directly to the printer. This is why commands such as _l_p_r, _l_p_r_m, and _l_p_q have to be used to access the printer. Because of this, users have to use _l_p_r to print a file. The _l_p_r command takes care of all the initial work needed to print the file, and then it hands control over to another program, _l_p_d, the line printing daemon. The line printing daemon then tells the printer how to print the file. When _l_p_r is executed, it first copies the specified file to a certain directory (the spool directory) where the file remains until _l_p_d prints it. Once _l_p_d is told that there is a file to print, it will spawn a copy of itself (what we programmers call forking). This copy will print our file while the original copy waits for more requests. This allows for multiple jobs to be queued at once. The syntax of _l_p_r(1) is a very familiar one, $ lpr [ options ] [ filename ... ] If filename is not specified, _l_p_r expects input to come from standard input (usually the keyboard, or another program's output). This enables the user to redirect a command's output to the print spooler. As such, $ cat thesis.txt | lpr or, $ pr -l60 thesis.txt | lpr The _l_p_r command accepts several command-line arguments that allow a user to control how it works. Some of the most widely used arguments are: -PPprinter specifies the printer to use, -hh suppresses printing of the burst page, -ss creates a symbolic link instead of copying the file to the spool directory (useful for large files), and -##num specifies the number of copies to print. An example interaction with _l_p_r might be something like $ lpr -#2 -sP dj thesis.txt This command will create a symbolic link to the file thesis.txt in the spool directory for the printer named _d_j, where it would be processed by _l_p_d. It would then print a second copy of thesis.txt. For a listing of all the options that _l_p_r will recognize, see _l_p_r(1). 22..33.. VViieewwiinngg tthhee PPrriinntt QQuueeuuee wwiitthh llppqq To view the contents of the print queue, use the _l_p_q command. Issued without arguments, it returns the contents of the default printer's queue. The returned output of _l_p_q can be useful for many purposes. $ lpq lp is ready and printing Rank Owner Job Files Total Size active mwf 31 thesis.txt 682048 bytes 22..44.. CCaanncceelliinngg aa PPrriinntt JJoobb UUssiinngg llpprrmm Another useful feature of any printing system is the ability to cancel a job that has been previously queued. To do this, use _l_p_r_m. $ lprm - The above command cancels all of the print jobs that are owned by the user who issued the command. A single print job can be canceled by first getting the job number as reported by _l_p_q and then giving that number to _l_p_r_m. For example, $ lprm 31 would cancel job 31 (thesis.txt) on the default printer. 22..55.. CCoonnttrroolllliinngg tthhee llppdd pprrooggrraamm wwiitthh llppcc The _l_p_c(8) program is used to control the printers that lpd serves. you can enable or disable a printer or its queues, rearrange entries within a queue, and get a status report on the printers and their queues. Lpc is mostly used in a setup where there are multiple printers hanging off one machine. $ lpc The above will start the lpc program. By default, this enters you into an interactive mode, and you can begin issuing commands. The other option is to issue an lpc command on the command line. $ lpc status all A list of the available commands are in the _l_p_d man page, but here are a few of the major commands you'll want to know about. Any commands marked with _o_p_t_i_o_n can either be a printer name (lp, print, etc) or the keyword all, which means all printers. +o disable _o_p_t_i_o_n - prevents any new printer job from being entered +o down _o_p_t_i_o_n - disables all printing on the printer +o enable _o_p_t_i_o_n - allow new jobs to enter the print queue +o quit (or exit) - leave lpc +o restart _o_p_t_i_o_n - restarts lpd for that printer +o status _o_p_t_i_o_n - print status of printer +o up _o_p_t_i_o_n - enable everything and start a new lpd 22..66.. TThhee RReeddHHaatt pprriinnttttooooll Just a quick note here on RedHat's amazing printtool program. It seems to do everything that a magicfilter would do. RedHat already installs many of the programs to do the filtering. Here's how I have my printer set up under RH 4.0 with an HP LJ 4L connected to my parallel port (should be the same for other versions of RH as well). +o Become root and fire up printtool (if you su'ed, you remembered to SETENV DISPLAY :0.0 and xhost +, right?) +o Click "Add", and hit "OK" for a local printer. +o Fill in the printer device (/dev/lp1 for me) +o Fill in the input filter - Select a printer type, resolution, and paper size (ljet4, 300x300, and letter) +o Hit "OK" all the way back, and restart the lpd. Just like rolling an /etc/printcap file by hand, you can have multiple printer definitions for each physical printer. One for different paper sizes, resolutions, etc. 33.. PPrriinnttiinngg ffiilleess This section covers printing the kinda of files that you'll run across in a Linux setup. 33..11.. PPrriinnttiinngg ggrraapphhiiccss ffiilleess Printing graphics files through a printer usually depends on the kind of graphics you're converting, and the kind of printer you want to send to. Dot matrix is usually out of the question due to differences in the way dot-matrix handles graphics. Your best bet in this situation is to see if your printer is compatable with an Epson or an IBM ProPrinter, then convert the graphics file to PostScript, then use Ghostscript (see next section) to print the graphics. If you have a laser printer, things are a bit easier since many are compatable with PCL. This now gives you a few options. Some programs may output directly in PCL. If not, programs like _N_e_t_P_B_M can convert into PCL. Last option is to use ghostscript (see next section). Your absolutely best option is to install packages like NetPBM and Ghostscript then installing a magic filter to process the graphics files automagically. 33..22.. PPrriinnttiinngg PPoossttSSccrriipptt ffiilleess Printing PostScript files on a printer that has a PostScript interpreter is simple; just use _l_p_r, and the printer will take care of all of the details for you. For those of us that don't have printers with PostScript capabilities, we have to resort to other means. Luckily, there are programs available that can make sense of PostScript, and translate it into a language that most printers will understand. Probably the most well known of these programs is Ghostscript. Ghostscript's responsibility is to convert all of the descriptions in a PostScript file to commands that the printer will understand. To print a PostScript file using Ghostscript, you might do something like $ gs -dSAFER -dNOPAUSE -sDEVICE=deskjet -sOutputFile=\|lpr thesis.ps Notice in the above example that we are actually piping the output of Ghostscript to the _l_p_r command by using the -ssOOuuttppuuttFFiillee option. Ghostview is an interface to Ghostscript for the X Window System. It allows you to preview a PostScript file before you print it. Ghostview and Ghostscript can both be swiped from . 33..33.. PPrriinnttiinngg PPDDFF ffiilleess Adobe has released an Acrobat reader for Linux, and it's available on the Adobe home page . Its predecessor, xpdf, is also available. Both should print to a postscript device. 33..44.. PPrriinnttiinngg TTeeXX ffiilleess One of the easiest ways to print TeX files is to convert them to PostScript and then print them using Ghostscript. To do this, you first need to convert them from TeX to a format known as DVI (which stands for device-independent). You can do this with the _t_e_x(1) command. Then you need to convert the DVI file to a PostScript file using _d_v_i_p_s. All of this would look like the following when typed in. $ tex thesis.tex $ dvips thesis.dvi Now you are ready to print the resulting PostScript file as described above. 33..55.. PPrriinnttiinngg ttrrooffff ffoorrmmaatttteedd ffiilleess $ groff -Tascii thesis.tr | lpr or, if you prefer, $ groff thesis.tr > thesis.ps and then print the PostScript file as described above. 33..66.. PPrriinnttiinngg mmaann ppaaggeess $ man man | col -b | lpr The man pages contain pre-formatted troff data, so we have to strip out any highlighting, underlines, etc. The 'col' program does this just nicely, and since we're piping data, the man program won`t use more. 44.. MMiisscceellllaanneeoouuss IItteemmss This covers topics not in any of the others. 44..11.. FFoorrmmaattttiinngg BBeeffoorree PPrriinnttiinngg Since most ASCII files are not formatted for printing, it is useful to format them in some way before they are actually printed. This may include putting a title and page number on each page, setting the margins, double spacing, indenting, or printing a file in multiple columns. A common way to do this is to use a print preprocessor such as _p_r. $ pr +4 -d -h"Ph.D. Thesis, 2nd Draft" -l60 thesis.txt | lpr In the above example, _p_r would take the file thesis.txt and skip the first three pages (+4), set the page length to sixty lines (-l60), double space the output (-d), and add the phrase "Ph.D. Thesis, 2nd Draft" to the top of each page (-h). _L_p_r would then queue _p_r's output. See its on-line manual page for more information on using _p_r. 44..22.. TThhee PPRRIINNTTEERR EEnnvviirroonnmmeenntt VVaarriiaabblleess All of the commands in the Linux printing system accept the -PP option. This option allows the user to specify which printer to use for output. If a user doesn't specify which printer to use, then the default printer will be assumed as the output device. Instead of having to specify a printer to use every time that you print, you can set the PRINTER environment variable to the name of the printer that you want to use. This is accomplished in different ways for each shell. For _b_a_s_h you can do this with $ PRINTER="printer_name"; export PRINTER and _c_s_h, you can do it with % setenv PRINTER "printer_name" These commands can be placed in your login scripts (.profile for _b_a_s_h, or .cshrc for _c_s_h), or issued on the command-line. (See _b_a_s_h(1) and _c_s_h(1) for more information on environment variables.) 55.. AAnnsswweerrss ttoo FFrreeqquueennttllyy AAsskkeedd QQuueessttiioonnss Q1. How do I prevent the staircase effect? A1. The staircase effect is caused by the way some printers expect lines to be terminated. Some printers want lines that end with a carriage-return/line-feed sequence (DOS-style) instead of the line- feed sequence used for UNIX-type systems. The easiest way to fix this is to see if your printer can switch between the two styles somehow---either by flipping a DIP switch, or by sending an escape sequence at the start of each print job. To do the latter, you need to create a filter (see Q2). A quick fix is to use a filter on the command-line. An example of this might be $ cat thesis.txt | todos | lpr Q2. What is a filter? A2. A filter is a program that reads from standard input (_s_t_d_i_n), performs some action on this input, and writes to standard output (_s_t_d_o_u_t). Filters are used for a lot of things, including text processing. Q3. What is a _m_a_g_i_c filter? A3. A magic filter is a filter that performs an action based on a file's type. For example, if the file is a plain, text file, it would simply print the file using the normal methods. If the file is a PostScript file, or any other format, it would print it using another method (ghostscript). Two examples of this is magicfilter and APSfilter. One caveat of these filters is that the appropriate programs have to be installed before you install the filter. The reason for this is that when the magicfilter gets installed, it queries your system for specific programs (such as ghostscript - if it finds it, then it knows it can handle PostScript data), then builds itself based on what it finds. To handle all the printer files, you should probably have at least the following installed: +o GhostScript +o TeX +o NetPBM +o jpeg utilities +o gzip Q4. What about the Windows Printing System? Will Linux work with that? A4. Maybe. Printers that accept only the WPS commands will not work with Linux. Printers that accept WPS and other commands (such as the Canon BJC 610) will work, as long as they're set to something other than WPS format. Other printers, such as some HP DeskJet 820Cxi/Cse, will *not* work with Linux. That being said, Linux can act as a print server (See Samba) for Win95 machines, since Win95 has drivers for those printers. Q5. What kinda cheey system is this? I can't print more than 6 pages or else I get a "file too large" error. A5. One of the options in the /etc/printcap file relates to the maximum size of a print file. The default is 1000 disk blocks (about 500k?). For PostScript files and the like, this will give you maybe 6-8 pages with graphics and all. Be sure to add the following line in the printer definition: mx=0 The primary reason for this is to keep the spool partition from get- ting filled. There is another way to do it, by making lpr create a soft link from the spool directory to your print file. But you have to remember to add the -s option to lpr every time. 66.. TTrroouubblleesshhoooottiinngg This section covers some common things that can go wrong with your printing system. If your printer doesn't work: +o Do other print jobs work? (application problem?) +o Is lpd running? (check it using lpc) (print controller?) +o Can root send something directly to the printer? (print services?) +o Can you print from DOS? (cable/printer problem?) Answering these questions can help find a solution. Send other suggestions for this section to . 77.. RReeffeerreenncceess This is a section of references on the Linux printing system. I have tried to keep the references section of this HOWTO as focused as possible. If you feel that I have forgotten a significant reference work, please do not hesitate to contact me. Before you post your question to a USENET group, consider the following: +o Is the printer accepting jobs? (Use _l_p_c(8) to verify.) +o Is the answer to your question covered in this HOWTO or Grant Taylor's Printing HOWTO? If any of the above are true, you may want to think twice before you post your question. And, when you do finally post to a newsgroup, try to include pertinent information. Try not to just say something like, "I'm having trouble with lpr, please help." These types of posts will most definitely be ignored by many. Also try to include the kernel version that you're running, how the error occured, and, if any, the specific error message that the system returned. OOnn--LLiinnee MMaannuuaall PPaaggeess +o _c_a_t(1) concatenate and print files +o _d_v_i_p_s(1) convert a TeX DVI file to PostScript +o _g_h_o_s_t_v_i_e_w(1) view PostScript documents using Ghostscript +o _g_r_o_f_f(1) front-end for the groff document formatting system +o _g_s(1) Ghostscript interpreter/viewer +o _l_p_c(8) line printer control program +o _l_p_d(8) line printer spooler daemon +o _l_p_q(1) spool queue examination program +o _l_p_r(1) off-line printer +o _l_p_r_m(1) remove jobs from the line printer spooling queue +o _p_r(1) convert text files for printing +o _t_e_x(1) text formatting and typesetting UUSSEENNEETT nneewwssggrroouuppss +o comp.os.linux.* a plethora of information on Linux +o comp.unix.* discussions relating to the UNIX operating system