In the past I’ve been pretty lucky writing documents in LaTeX and printing them. Usually I render the document to PDF using pdflatex, then print it from the Mac’s Preview app. Usually this has worked without incident!

Options from lpr

If you move outside the cozy convenience of Preview’s printer configuration dialog, into the ascetic austerity of the command line, you sometimes still need to control some of the printers’ options. Runes like this work:

lpr -o media=A4 -o PageSize=A4 -o sides=two-sided-long-edge
    -o InputSlot=Tray1 foo.pdf


Some fancy printers can staple documents after they’re printed. Often you can enable this from the printer driver, but this is not an option if you’re printing from a USB stick plugged into the printer. This sort of thing, which encompasses stapling, folding, and sometimes even stitching is referred to as finishing.

In such circumstances, you can enable the stapler by embedding PJL1 commands into the file. I tried this with PCL2 files, but I think similar tricks work in PostScript.

The key runes are:


Which you can interpolate with this Perl snippet:

$pcl =~ s/(\@PJL)/\@PJL SET FINISH=STAPLE\n$1/;

Printers will often let you pick one of several options for placing the stamples, and the SET STAPLEOPTION PJL command can configure this. I’ve not explored this though.

Ghostscript support

It is possible that you’ll be able to enable this via a command line switch on gs in the near future. For more details see the enhancement request.3

Fixing questionable PDFs

I have a couple of HP printers: a monochrome P3010 series, and a colour M476dw. The former has very few problems, but the latter has trouble printing files rendered with pdflatex: all the fonts get replaced by Courier.

Doubtless the is some misconfiguration or misunderstanding somewhere, but I couldn’t find it. Instead, running the pdf file through Ghostscript fixes the problem:

$ gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=ok.pdf bad.pdf

Printing from USB on SHARP printers.

There is a fine gotcha here: if the printer doesn’t recognize the file, it simply omits it when showing the directory listing. So, if you put PostScript files (or perhaps more accurately files with a .ps suffix) onto a USB stick, you won’t see them if the printer in question only understands .PCL files.

Incidentally, Ghostscript’s pxlcolor device is a good way to get PCL files:

$ gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pxlcolor -sOutputFile=foo.pcl foo.pdf

Tweaking the printer drivers in OS X

I have a couple of HP printers and when I tried to print a PDF generated from LaTeX it worked perfectly on one, and failed with mangled fonts on the other. Printing the same file to the buggy printer from Windows worked, so I suspected the printer driver was at fault.

I think the problem stems from the Mac auto-detecting the wrong driver. Messing around on the Internet suggested that I should be using the driver in:

/Library/Printers/PPDs/Contents/Resources/HP Color LaserJet Pro MFP M476.gz

Happily it’s fairly easy to specify the driver manually with the CUPS web-interface.

To enable this:

sudo cupsctl WebInterface=yes

Then visit:


and follow the instructions.