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.”

8 Comments
8 of 8 people learned something from this entry.

  1. Patrick Widener said,

    January 14, 2009 at 2:39 pm

    (Learned something new!)

    The issue of #2 was driving me nuts. Thanks very much for writing this up.

  2. Hermano Cabral said,

    February 15, 2010 at 8:58 pm

    (Learned something new!)

    Thanks for the information. I was trying to make pdf express to accept a pdf file generated with dvipdfm + eps figures but wasn’t having any luck. With your tip of replacing fonts in the eps files, everything worked just fine. Also, pdffonts is a worthwhile program. Didn’t have a problem finding it in my Ubuntu 9.10 box. Thanks a lot.

  3. JVitku said,

    March 25, 2014 at 5:50 am

    (Learned something new!)

    Hi, thanks for the info, solution to the issue #2 seemed to me a but complicated. I found this http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig

    which works flawlessly and solves the issue.

  4. Nit said,

    July 3, 2014 at 4:02 pm

    (Learned something new!)

    Thanks for this post!
    I was desperately trying to find a solution for the same problem you mention and your workaround works around ;-)

  5. white_blue said,

    October 23, 2014 at 2:47 am

    (Learned something new!)

    Very useful! Thanks. Especially the part how to edit eps file to use open fonts

  6. Jasper said,

    October 30, 2014 at 10:32 am

    (Learned something new!)

    I found that for dvips you can use the -j0 flag, which still yields an error message but it displays the fonts correctly.

    See also first faq here: http://www.radicaleye.com/dvips.html

  7. James said,

    February 4, 2015 at 8:22 am

    (Learned something new!)

    Thanks, this helped for my dissertation!

  8. Andre Lage said,

    June 17, 2015 at 10:13 am

    (Learned something new!)

    Thanks for writing the topic “2. Replace proprietary font names with their open-source equivalents”.

    However, in OS X Yosemite (10.10.2), I fixed the problem by updating ghoscript through macports:

    $ sudo port install ghostscript

    Maybe the new version managed to download proprietary fonts, I actually don’t know how it was exactly solved.

Post a Comment

I knew this already. I learned something new!