Tuesday, September 18, 2007

Text to Postscript: a2ps

Sometimes I need to convert a text file to a postscript file either to print it or to include it in a paper as an eps file. To do this, I use the a2ps command, but as with symlinks, I tend to forget the options. The man page for a2ps is quite useful. Just for fun, I give some examples of how I use a2ps below.

If I just want to print a text file for my own viewing, I do the most basic:
a2ps my-file.txt -o my-file.ps

This tells a2ps to take the input file my-file.txt and print it to the ps file my-file.ps. By default, this puts two virtual pages per sheet of paper as well as borders around columns. It also adds header and footer information about the file. If you want to print more virtual pages per sheet, you can add a flag with the number of pages per sheet up to nine. So if you want four per sheet, change the above to:
a2ps -4 my-file.txt -o my-file.ps

In this next example, I wanted to create an eps file out of some code. I wanted line numbers, no headers, and no borders. I did it using the following:
a2ps code-file --borders=no -B --line-numbers=1 -1 -o output-file.eps

Not surprisingly, --borders=no turns off borders. -B turns off headers. --line-numbers=1 tells a2ps to print every line number. -1 prints a single page per sheet of paper and -o output-file.eps tells a2ps the name of the output file. Obviously, replace code-file and out-put-file.eps with the file names you want. Again, the man pages include useful information about these and other options.

No comments: