Embed all fonts in PDFs generated with LaTeX or PDFLaTeX

For high quality publications it is absolutely mandatory to embed all fonts in the respective PDF. If a PDF does not embed all fonts, the target system may replace the respective font with the 'best' available system font, so the document is almost certain to look different on different machines. Not quite what you want from a portable document standard, is it?

In the following I will explain how you can make sure that all fonts are embedded in your LaTeX documents (journal papers, conference contributions, flyers, etc.). Some tricks will even apply to PDFs in general and not be specific to LaTeX. There is also a small tarball available for download with all the details so that you can reproduce (and use for copy&paste) the subsequent discussion.

Embedding All Fonts with PDFLaTeX

If you use PDFLaTeX and do not include any figures, you may not need to do anything other than verify that all fonts are indeed embedded. This can be achieved with either your favorite PDF viewer, or on the command line with pdffonts:

pdffonts my_file.pdf

The tool prints a table listing all the fonts used in the PDF. The third column says 'yes' if the font is embedded, and 'no' if the font is not embedded. Here is a sample output from pdffonts for a PDF with all fonts embedded:

name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------
XAUHVA+CMR17                         Type 1            yes yes no       4  0
EKPMOY+CMR12                         Type 1            yes yes no       5  0
CMJFHY+CMTI10                        Type 1            yes yes no       6  0
BYGDYG+CMBX12                        Type 1            yes yes no       7  0

Overall, if your document does not include externally generated figures, most likely your fonts are properly embedded when using PDFLaTeX. Some figures (usually in PDF format) included in your document may, however, result in fonts not being embedded. Read on to see how to fix these.

Embedding All Fonts with LaTeX

If you use LaTeX to produce a DVI file, dvips to produce a postscript file, and ps2pdf to generate the PDF, you should check for embedded fonts just like described for PDFLaTeX above. If some fonts are not embedded, you can instruct ps2pdf to embed all fonts by passing the options -dPDFSETTINGS=/prepress -dEmbedAllFonts=true as follows:

latex my_file.tex
dvips my_file.dvi
ps2pdf -dPDFSETTINGS=/prepress -dEmbedAllFonts=true my_file.ps

On my system it turned out to be sufficient to just pass -dPDFSETTINGS=/prepress. The ps2pdf call above is essentially the same as calling Ghostscript directly, e.g.:

gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dEmbedAllFonts=true -sOutputFile=my_file_embedded.pdf -f my_file.ps

If you already have a file my_file.pdf with fonts not embedded, you can also use the Ghostscript command above to produce a new PDF with all fonts embedded. Just replace 'my_file.ps' with 'my_file.pdf' above.

Instead of using dvips and ps2pdf, you may also use dvipdfm to generate a PDF directly from a DVI file:

latex my_file.tex
dvipdfm my_file.dvi

My experiments showed that dvipdfm does not embed fonts which are missing in postscript graphics. In such case, I recommend dvips and ps2pdf with the options discussed above.

Embedding All Fonts in Figures

Postscript or PDF figures may or may not include all their fonts. My experiments indicated that fonts are embedded in the final document if the font is embedded in the respective figure. Similarly, if a figure does not embed all its fonts, usually the respective fonts are not embedded in the final document either. Consequently, we have two options for embedding all fonts: Either make sure that all fonts are embedded in each figure, or post-process the resulting PDF document (and don't forget to do the same with every other document in which you use that particular figure).

If you use Gnuplot, the resulting figures will most likely have their fonts embedded. The statistics package R, however, produces postscript and PDF plots without embedded fonts. Use one of the following three options to get your fonts embedded in PDF plots generated from R:

  1. Let R generate postscript (.eps) files and convert them to PDF with epstopdf.
  2. Use cairo_pdf() instead of pdf() in R to export your plots as PDF.
  3. Use Ghostscript to embed all fonts in the figure:
    gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dEmbedAllFonts=true -sOutputFile=my_plot_embedded.pdf -f my_plot.pdf

Each of the three options will result in PDF plots with fonts embedded.

If you cannot (or do not want to) alter your figures, you can also use the Ghostscript command above on your full document.

Samples

I collected my results for checking the embedding of fonts for the ACM SIG Proceedings Template, the Elsevier class elsarticle, the IEEE proceedings class IEEEtrans, and the Springer journal template svjour3. The tarball also contains the scripts for my experiments with figures generated from Gnuplot and R.

>> Download tarball with code samples for embedding fonts with LaTeX and PDFLaTeX <<

This blog post is for calendar week 1 of my weekly blogging series for 2016.