home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 43.21 Preprocessing troff Input with sed Chapter 43
Next: 43.23 psselect: Print Some Pages from a PostScript file

43.22 Converting Text Files to PostScript

Printing used to be easy; when all we had were daisy wheel printers and line printers, you could send virtually any text file to a printer without modification. That's no longer possible; fancy "printer languages" like PostScript force you to do a fair amount of processing to get a simple text into some form that the printer can understand.

As always, there are several ways to solve this problem. The first is gross and disgusting, but quite effective. Assume that you have a working version of troff with the -ms macros. Here's the script:

# the name of the script that runs troff for you
# choose your favorite macro package
sed -e '
.in 0\
.ft CW\
.ps 10\
.vs 12
.DE ' | $roff $macros

How does it work? It just "wraps" your text with a troff incantation that prints the text in a fixed-width font, with no "justification" or "fill." It relies on the ms macro package to handle margins, new lines, page numbers, and so on. The sed script also massages your file so that it will print anything that troff finds confusing - in particular, backslashes and lines beginning with periods or single quotation marks. In fact, it can even print a troff macro package; if memory serves me, that's why I originally wrote it.

I like this because it works as well as any other solution I've seen, and better than most; it's extremely simple; and, because it uses UNIX tools to do the work they were designed to do, it's a good demonstration of the UNIX philosophy. It's even elegant in its own bizarre way. And, if you know a little bit (not much) about troff , you can customize it for your own situation.

However, there are other solutions. Perhaps the best is to use the enscript program, which is part of Adobe's transcript package. That's proprietary software, so we can't include it with this book. But at least we can point you in the right direction.

One option that's "free" is Dan Judd's pstext program. Though it's small, it provides a lot of features. It emulates a standard line printer: it interprets form feeds as page breaks, handles backspaces and tabs appropriately, lets you vary the margin, the number of lines per page, and so on. Here's how to use it:




options file1 file2 ... 

| lpr

There are a zillion options, but the most important are:


Print "landscape" (across the page, the long way); by default, printing is "portrait" (down the page).


Print landscape, "two-up" (two logical pages per physical page)-not too useful, unless your source file has short lines.


Print portrait, "two up."

-s p

Use a font of size p (in points).

-f name

Use the font with the given name .

-n n

Print n lines per page.

- ML

Previous: 43.21 Preprocessing troff Input with sed UNIX Power Tools Next: 43.23 psselect: Print Some Pages from a PostScript file
43.21 Preprocessing troff Input with sed Book Index 43.23 psselect: Print Some Pages from a PostScript file

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System