20100527

The command line PostScript swiss knife: a2ps

I discovered this tool by accident, when a colleague asked me why I printed a .txt file straight without using a2ps first. My first reaction of course was thinking What? and promptly asking google.

Google answered with this page, and it was interesting enough to deserve an apt-get install. And indeed, it is great! Usually, when I have some straight text file I need to print, I use emacs old postscript-print-buffer, which is nice, but not as nice as all options a2ps has.

As default, a2ps prints in landscape format, 2 pages per sheet. Moreover, it adds a black border around the page and a header with the filename, time and who printed this. Below an example of straight a2ps:



Back a few days ago I had to print my flight details (it was too early to print the boarding pass), and you know, they look like a nicely formatted text file. But when Gmail tries to print it, it removes all white spacing, rendering it unreadable.

A solution? Creating a flight.txt file and pasting from the mail. Then
a2ps flight.txt -B --portrait --columns=1 -o flight.ps
What does all this mean?
  • -B removes the header, which is useful only if more than one sheet is needed,
  • --portrait turns on portrait print mode (landscape by default),
  • --columns=1 Just one page per sheet. 2 by default,
  • -o output file name. By default it would send to the default printer,
And the same example with these settings:



There are also other interesting options. For example -catman (or -m) selects 66 lines per page, as if the job comes from a man page. A companion program to a2ps is card: turns man pages into pretty PostScript files. Its usage is simple:
card a2ps -o a2ps.ps
Generates the manual entry for a2ps for pretty printing:



The card program invokes a2ps, thus you can add a2ps options after --, for instance
card a2ps -o a2ps.ps -- -B to remove the headers



a2ps' slogan is Do the right thing, meaning that it will pass the processing to any other processor. For example, if trying to process html files, it will pass them to html2ps, if you try a gif file, it will pass it to ImageMagick.

This is only meant as an introduction to a2ps, as it has around 50 options for processing files. For more info... man a2ps :)

Related posts:
My first port to the Ben NanoNote: gnugo
Power to the command line
Two weeks, still loving Fluxbox
Three dee (3-dimensional file system browsers review)
Gcal: the ultra-powerful command line GNU calendar
Acer Aspire One 8.9' + Ubuntu + Fluxbox

Written by Ruben Berenguel