Friday, February 10, 2012

EPS figures: Embedding Fonts

Many journal publishers, including AIP, now demand EPS figures with fonts embedded. If you have Adobe Acrobat, then this is a trivial issue.

But Acrobat is not free.

[Side Note: Most of my figures for journal articles come from two programs: Inkscape for schematics, and Grace for plots. Inkscape supports embedding fonts in EPS directly. Grace currently does not (v5.1), but will do so in the near future (apparently v5.99 already has it).]

But here let us assume you have a generic EPS file which does not have fonts embedded. The process described here (which seemed to satisfy AIP) involves converting the EPS to a PDF, embedding fonts, and then converting back again.

But first, how would you find out whether your fonts are embedded? There are at least two ways. But first you need to convert the EPS to a PDF.

epstopdf unembed.eps [creates unembed.pdf]

Once you have a PDF you can:

(i) pdffonts unembed.pdf: On the particular file I am working on I get:

name           type         emb sub uni object ID
-------------- ------------ --- --- --- ---------
Times-Roman    Type 1       no  no  no       8  0
Symbol         Type 1       no  no  no       9  0
Times-Bold     Type 1       no  no  no      10  0


The key thing to note is the "no no no" under the "emb"(edded) field.

(ii) or, you can open the PDF in Adobe Reader. If you look at File -> Properties -> Fonts tab (in Adobe Reader 9 running on Linux), you will see something that looks like:
The key is you don't see the word "embedded" anywhere.

The next step is to embed the fonts in the PDF using some ghostscript black magic. You say (change only the filenames in red):

gs -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=letter -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=embed.pdf -f unembed.pdf

Now you check whether fonts have been embedded in "embed.pdf".

pdffonts embed.pdf
 
name               type         emb sub uni object ID
------------------ ------------ --- --- --- ---------
KKRTRL+Times-Roman Type 1C      yes yes no       9  0
VMUCKG+Symbol      Type 1C      yes yes no      11  0
CNFCZN+Times-Bold  Type 1C      yes yes no      13  0


As you can see fonts have been "emb"edded. Or you can check it in Adobe Reader.


Finally, we convert the PDF back to EPS with:

pdftops -eps embed.pdf embed.eps

One caveat: As decribed here, you could have trouble (the ghostscript step may complain with some warnings, for example) embedding the font if your system doesn't have a mapping for it.
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:

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 b4unembed.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' > unembed.eps

2 comments:

Michael said...

Thanks! You're a lifesaver!

Anonymous said...

That was very useful, thank you! It looks like inkscape 0.48.3.1 does embed fonts, or at least all of my inkscape-exported pdfs show up as having embedded fonts with pdffonts - but I wouldn't have known how to check that if it wasn't for this post!