Tumbled Logic

Dec 7 2006

Using a2ps on Mac OS X

Depending upon your printer setup, you may find that a2ps won’t work on Mac OS X. It’ll generate PostScript just fine, but Mac OS X’s printing subsystem can fail. If you have a PostScript printer, things will probably just work, but if you have some other kind (for example, one of the recent crop of cheap laser printers that use a custom page description language), you’ll run into problems.

Fortunately, the solution is quite simple: you just have to convert the PostScript output of a2ps to PDF before sending it to the printer.

To accomplish this, you need to install two things: GhostScript (I used GNU GhostScript) and a set of fonts. I used the ‘standard’ fonts linked to from this page on Ghostscript fonts, which pointed me at this FTP server.

On Mac OS X, I found that GNU Ghostscript required a tiny patch in order to compile properly. In jasper/src/libjasper/jpc/jpc_cs.c, just underneath the line reading #include “jpc_cs.h”, add:

typedef unsigned long ulong;

With this modification, GNU Ghostscript should build and install without incident.

To install the fonts, simply copy the .afm, .pfb and .pfm files to somewhere within the Ghostscript search path. If you configured and installed with no special options, you will want to copy the files to /usr/local/share/ghostscript/fonts.

Next, you need to configure a2ps to use Ghostscript to generate PDF output before sending it to the printer. Ghostscript includes a utility, ps2pdf, for this purpose (along with variants for generating different PDF versions, such as ps2pdf14 to generate PDF 1.4 output).

In your a2ps-site.cfg, comment out the line starting DefaultPrinter: and replace it with:

Defaultprinter: | ps2pdf -sPAPERSIZE=a4 - | lp

The -sPAPERSIZE=a4 instructs Ghostscript to generate a PDF that uses A4 paper dimensions; you may need to adjust this to suit your requirements. You should ensure that a2ps’s own settings agree with the paper size you specify here.

To test your installation, simply run a2ps /path/to/file from the command-line. For example:

a2ps Projects/hello-world.c

After a few moments, an a2ps-formatted document should emerge from your printer.

In addition to the above, you might want to configure a2ps to generate a PDF file and leave it on your desktop for distribution or printing later. Fortunately, this is easily accomplished.

Again, in your a2ps-site.cfg add:

Printer: pdf | ps2pdf -sPAPERSIZE=a4 - > ${HOME}/Desktop/$N.pdf

To test this, run:

a2ps -P pdf Projects/hello-world.c

This should create a PDF file called hello-world.pdf on your desktop. You can open it in Preview (and do anything else that you would typically do with a PDF) as normal.


blog comments powered by Disqus
Page 1 of 1