Tuesday 26 February 2013

Embedding fonts in an existing EPS image

Today, I was wanting to submit an EPS figure (prepared by a colleague) to a journal. However, the EPS image I was given did not have fonts embedded, and this caused horrible results when the online production software converted it to PDF. The solution was to use a little command-line magic to convert the image to PDF, embedding the necessary fonts and then convert it back to EPS. This little code snippet shows how it's done. It could easily be converted into a script!
  #! /bin/sh -e

  # Define the input file (without .eps extension)
  FILE=Fig1

  # Convert to PDF and embed fonts
  ps2pdf14 -dPDFSETTINGS=/prepress -dEPSCrop -dEmbedAllFonts ${FILE}.eps tmp.pdf

  # Output the new EPS file
  pdftops -eps tmp.pdf ${FILE}-embedded.eps

  rm tmp.pdf
Note the use of the -dEPSCrop option to preserve the page size.