How to embed fonts in a PDF file

This is an issue that comes up every now and then, for example when you create a PDF file that’s designed for actual printing (like in a book). The fonts used by PDF (or PS) files can be either embedded or simply “linked” to fonts already installed on the system. The advantage to linking is that the file size can be a lot smaller; the PDF file doesn’t need to carry around a full description of how to render each font. Unfortunately, the destination system doesn’t always have the fonts you want. The safest solution is to embed every font description in the PDF file.

But how do you make this magic happen? There are two important steps I learned about today. (These apply to linux/unix/Mac systems.)

1. Tell pdflatex, dvips, and dvipdf to embed the fonts.

The best instructions I’ve seen for this are here. Basically, you run `updmap` to find out where your config file is, then edit it to indicate that you want the fonts to be embedded. Re-run `updmap` to make those config settings stick, and then you can do pdflatex or dvips or dvipdf (as desired) to create files with embedded fonts.

That will get you most of the way there. However, if you’re including figures (say, .eps files) that also have their own fonts that weren’t embedded, and those font names aren’t recognized, you may get an error like:

dvips: Font Helvetica used in file fancy_widget.eps is not in the mapping file.

You can’t embed the font if your system doesn’t have a mapping for it. Oops! This usually happens with fonts like Helvetica, Times, and Symbol; these are proprietary font names, so their mappings aren’t found in most open source systems. But you can fix this problem, as described in this excellent font reference, by replacing the font names with their open-source equivalents:

2. Replace proprietary font names with their open-source equivalents.

Since .eps is a text format, you can just open the .eps file in a text editor and search/replace the font names. Markus Neteler makes this even easier with a handy bit of sed:

cat original_graphics.eps | sed 's+Times-Bold+NimbusSanL-Bold+g' |\
sed 's+Times-Roman+NimbusSanL-Regu+g' |\
sed 's+Times+NimbusSanL-Regu+g' |\
sed 's+Helvetica-BoldOblique+NimbusSanL-BoldItal+g' |\
sed 's+Helvetica-Oblique+NimbusSanL-ReguItal+g' |\
sed 's+Helvetica-Bold+NimbusSanL-Bold+g' |\
sed 's+Helvetica-Bold-iso+NimbusSanL-Bold+g' |\
sed 's+Helvetica+NimbusSanL-Regu+g' |\
sed 's+Helvetica-iso+NimbusSanL-Regu+g' |\
sed 's+Symbol+StandardSymL+g' > new_graphics.eps

For the particular file I was working on today, a couple of additional fonts didn’t show up on Markus’s list. They were all variants on the Courier font. After some hunting around, I figured out that Courier is “Nimbus Mono L”, so here’s the translation:

Courier NimbusMonL-Regu
Courier-Bold NimbusMonL-Bold
Courier-Oblique NimbusMonL-ReguObli
Courier-BoldOblique NimbusMonL-BoldObli

Finally, you may want to check the file to confirm that the fonts were embedded. It seems that you can use a utility called ‘pdffonts’ to do this from the command-line, but I don’t have it on my system. Alternatively, you can fire up Adobe Reader, go to “File->Document Properties”, click on the “Fonts” tab, and browse to see that each font is marked “embedded.”