< Previous | Contents | Next >
Another Option: a2ps
The a2ps program is interesting. As we can surmise from its name, it’s a format conver- sion program, but it also much more. Its name originally meant “ASCII to PostScript” and it was used to prepare text files for printing on PostScript printers. Over the years, however, the capabilities of the program have grown, and now its name means “Anything to PostScript.” While its name suggests a format-conversion program, it is actually a printing program. It sends its default output to the system’s default printer rather than standard output. The program’s default behavior is that of a “pretty printer,” meaning that it improves the appearance of output. If we use the program to create a PostScript file on our desktop:
[me@linuxbox ~]$ ls /usr/bin | pr -3 -t | a2ps -o ~/Desktop/ls.ps -L 66
[stdin (plain): 11 pages on 6 sheets]
[Total: 11 pages on 6 sheets] saved into the file `/home/me/Desktop/ ls.ps'
[me@linuxbox ~]$ ls /usr/bin | pr -3 -t | a2ps -o ~/Desktop/ls.ps -L 66
[stdin (plain): 11 pages on 6 sheets]
[Total: 11 pages on 6 sheets] saved into the file `/home/me/Desktop/ ls.ps'
Here we filter the stream with pr, using the -t option (omit headers and footers) and then with a2ps, specifying an output file (-o option) and 66 lines per page (-L option)
to match the output pagination of pr. If we view the resulting file with a suitable file viewer, we will see this:
Figure 6: Viewing a2ps Output
As we can see, the default output layout is “two up” format. This causes the contents of 2 pages to be printed on each sheet of paper. a2ps applies nice page headers and footers, too.
a2ps has a lot of options. Here is a summary:
Table 22-4: a2ps Options
Option Description
Option Description
--center-title=text Set center page title to text.
--columns=number Arrange pages into number columns. Default is 2.
--footer=text Set page footer to text.
--guess Report the types of files given as arguments. Since a2ps tries to convert and format all types of data, this option can be useful for predicting what a2ps will do when given a particular file.
--left-footer=text Set left-page footer to text.
--left-title=text Set left-page title to text.
--line-numbers=interval Number lines of output every interval lines.
--list=defaults Display default settings.
--list=topic Display settings for topic, where topic is one of the following: delegations (external programs that will be used to convert data), encodings, features, variables, media (paper sizes and the like), ppd (PostScript printer descriptions), printers, prologues (portions of code that are prefixed to normal output), stylesheets, and user options.
--pages=range Print pages in range.
--right-footer=text Set right-page footer to text.
--right-title=text Set right-page title to text.
--rows=number Arrange pages into number rows. Default is one.
-B No page headers.
-b text Set page header to text.
-f size Use size point font.
-l number Set characters per line to number. This and the
-L option (below) can be used to make files paginated with other programs, such as pr, fit correctly on the page.
-L number Set lines per page to number.
-M name Use media name. For example, “A4”.
-n number Output number copies of each page.
-o file Send output to file. If file is specified as “-”, use standard output.
-P printer Use printer. If a printer is not specified, the system default printer is used.
-R Portrait orientation.
-r Landscape orientation.
-T number Set tab stops to every number characters.
-u text Underlay (watermark) pages with text. This is just a summary. a2ps has several more options.
Note: There is another output formatter that is useful for converting text into Post- Script. Called enscript, it can perform many of the same kinds of formatting and printing tricks, but unlike a2ps, it only accepts text input.