be in it too. /usr/share/games/fortune/bofhexcuses
LPIC topic 1.107.3 — Print files [1]
Weight: 1 Objective Candidates should be able to manage print queues and manipulate print jobs. This objective includes adding and removing jobs from configured printer queues and converting text files to postscript for printing. Key files, terms, and utilities include lpr submit a print job lpq show the printer queue mpage text to postscript conversion (and more)7.1 What is postscript
PostScript is a programming language that communicates a document description to a printing system in a deviceindependent way. Postscript was was used as a page description language by the Apple LaserWriter. Its primary application is to describe the appearance of text, graphical shapes, and sampled images on printed pages. PostScript is an unusually powerful printer language because it is a full programming language, rather than a series of lowlevel escape sequences, such as is used by terminals. Postscript is the standardised format for printing in Linux. Every program that wants to print something converts it to postscript. Every printer that needs to print on Linux converts postscript to its own printing format, such as PCL (for a postscript printer no conversion may be necessary).To submit a job to a printer, use lpr. To view the printer queue, use lpq. (For good measure,
lprm removes print jobs). Notice that the output of lpq shows the filename submitted to the print system.
foo:~ $ ls -la *.ps
-rw-rw-r-- 1 donaldd donaldd 164531 Jan 31 14:35 blah.ps foo:~ $ lpr -P lp1 blah.ps
foo:~ $ lpq -P lp1
lp1 is ready and printing
Rank Owner Job File(s) Total Size active donaldd 1260 blah.ps 164864 bytes foo:~ $ lprm -P lp1 1260
foo:~ $ lpq -P lp1
lp1 is ready no entries
7 Postscript LPI 102 Course Notes 47
7.2 mpage
If you send ASCII text straight to your printer, it will probably print, but will use a lot of paper. It will also print the text against the left margin, in the default font. mpage converts ASCII text to multiple pages of postscript, organising it into columns and fitting many pages onto a single sheet (in smaller type). You can also change the font and other important details.
mpage x shows the default values for the various settings in brackets. In the example below, mpage generates 4 pages per sheet, in the updown layout, and formats the output for “Letter” size paper (rather than A4 or something similar).
foo:~ $ mpage -x
mpage - print multiple pages on postscript, version 2.5.2pre August 1999
mpage [-1248acEfHlkoOrRStvxX] [-b papersize] [-Btextboxmargin] [-C [encodingfile]] [-da|p] [-D dateformat] [-F fontname] [-h header] [-I indent] [-j pagespec] [-L lines]
[-msheetmargin] [-Mpagemargin] [-p[prprog]] [-P[printer]] [-s tabstop] [-W width] [-X [header]] [-z printcmd] [-Z
quearg] [file...]]
-1, -2, -4, -8 Pages per sheet (4) -D strftime format for date specs
-da Force ascii input format -dp Force postscript input format
-a Toggle across/updown layout (u) -l Toggle portrait/landscape (p)
-f Toggle folding long lines (off) -o Toggle printing outlines (on)
-r Reverse printing, last->first sheet -v Toggle verbose output, (on)
-F Text font to be used (Courier) -C Character encoding filename
-E Print every second and third page -O Print every 1st and 4th
page
-s Define tabstop width (8) -k kill on %TRailer is PS file
-b papersize (Letter), use l of ? to get a list of sizes
mpage can print 1, 2, 4 or 8 pages per sheet.
% mpage /etc/services # default behaviour
% mpage /etc/services > services.ps
% gv services.ps # default is ...
% cat /etc/profile | mpage -1 | gv -
The output of mpage is postscript, which can be sent to lpr for printing. mpage
accepts the P option like lpr for specifying the printer. If P is given, the output is automatically printed.
% mpage -8 /etc/protocols | lpr
% mpage -8 -Plp0 /etc/protocols
% lpq -Plp0
name of a PostScript font.
% mpage -1 -F Helvetica /etc/inittab | gv -
% mpage -1 -F Times /etc/inittab | gv -
To send the output to particular printer, you use the P option. The first example here is incorrect – mpage undestands that you wish to print to the default printer, in particular the files lp1 and /etc/protocols.
foo:~ $ mpage -8 -P lp1 /etc/protocols
mpage: cannot open lp1
mpage: No such file or directory
Here's the right way to do it ...
foo:~ $ mpage -8 -Plp1 /etc/protocols
foo:~ $ lpq -P lp1
lp1 is ready and printing
Rank Owner Job File(s) Total Size active donaldd 1259 (stdin) 26624 bytes
mpage H prints headers for each file printed. These examples also illustrate the use of the c option to concatenate multiple files onto a single sheet.
foo:~ $ mpage -H /etc/p* - | gv -
foo:~ $ mpage -c -H /etc/p* - | gv -
mpage b is used to print to a specific type of paper. Here are just a few of the paper sizes that mpage supports.
foo:~ $ mpage -bl
Mpage knows about the following paper types: Type Points Wide Points High
--- --- --- Letter 612 792 Legal 612 1008 A4 596 842 A4Small 595 842 foo:~ $ mpage -b A4 -H -2 -c /etc/h* | gv -
foo:~ $ mpage -b A5 -H -2 -c /etc/h* | gv -
While mpage is most often used for formatting text output, it can also be used to format postscript output, and reduce the amount of paper used in printing. Here we generate two postscript files using mpage – but we could have used two arbitrary postscript files.
foo:~ $ mpage -1 -H /etc/hosts.allow > hosts.allow.ps
foo:~ $ mpage -1 -H /etc/hosts > hosts.ps
foo:~ $ mpage -2c hosts*.ps | gv -
7.3 Review
Quiz questions
1. What is postscript?
2. Which command removes a print job from the queue?
3. How does one specify that mpage or lpr must print to a specific printer?
7 Postscript LPI 102 Course Notes 49 displayed. What is wrong? 5. What is the command to print a text file using 4 pages per sheet on A4 paper, with headings? Assignments 1. If you have access to a Windows system, set up an Apple LaserWriter printer driver which writes to a file. To what extent are files generated by Windows compatible with the Linux printing system, e.g. with gv (for viewing), pstopdf (for converting to PDF) and lpr for your printer?
2. Generate a document from another application (not mpage) and print it two pages per sheet using mpage. What are the options to mpage that you had to use?
3. Investigate the a2ps utility and compare it to mpage. Why would you use a2ps rather than
mpage to print /etc/profile?
4. How does enscript compare to a2ps? What additional functionality does it offer?
Answers to quiz questions
1. A document formatting language with backward syntax (commands after parameters). 2. lprm
3. Pprinter
4. If you run mpage P lp2 then you have specified the printer as “” and the file to print as
lp2.