Saturday, October 20, 2001

Converting Files to Postscript

a2ps (Anything to PS) is a program that converts files to PostScript, the language used for graphics and understood by many printers, especially laser printers. You might want to use a2ps for example to print "text files" (like email) in both sides of the paper in a printer with duplex option. Or you can also use it to print "two pages in one," that is, reduce the size of each page by 50% and print two of them in one single sheet of paper.

Without any options you can use the command like this:

a2ps file-name

This will convert the file file-name into a PS file; the output will come to the terminal, which is not very useful unless you can either save it or process it further. To save the output in a file you can do the following:

a2ps -o output-file file-name

To print the file directly (in a printer that understands PS) you could do this:

a2ps file-name | lpr -Pprinter-name

(I have not explained yet the lpr command; I will do it in a future post).

The above option (sending the file to a printer) can be done with an option of a2ps as follows:

a2ps -P printer-name file-name

There are many different options for a2ps. Here are some useful ones.

  1. -r to print in landscape mode, -R in portrait mode
  2. -1, -2,…, -9 to have 1, 2,…, 9 pages printed in a single sheet of paper (I find -2 and -4 the most useful options).
  3. -j to print borders around columns, –borders=no for no borders
  4. -B (or –no-header) for no header information (which usually contains the file name, user, date and things like that, printed at the top of the pages).
  5. –font-size=SIZE to use fonts of certain SIZE
  6. -L NUM to scale fonts to print NUM of lines per page
  7. -l NUM to scale fonts to print NUM of colums per page
  8. -b TEXT to put TEXT as the header of the pages
  9. –left-title TITLE and –right-title TITLE to set titles at the left and right ends of the pages
  10. -c or –truncate-lines=no to cut or not long lines
  11. -i or –interpret=no to understand TABS or not
  12. –print-anyway=yes or –print-anyway=no to force or not binary printing
  13. -P printer-name to send output directly to the printer (via the printing program of your machine)
  14. -n NUM to print NUM of copies of each page

You can look at the manual page for more information. I use a2ps in two different ways:

a2ps -r -2 -j –no-header -i

and

a2ps -r -2 -j -i

to print with and without headers respetively, "two pages in one" in landscape mode.