Saturday, September 6, 2014

LaTeX: Embedding All Fonts in PDF

Many publishers are cautions about readers' experience and want to ensure all fonts are embedded in PDF files when you send your final camera-ready PDF files in.

We commonly use LaTeX to produce publication grade PDF files. However, some publishers warn about the use of pdflatex to compile LaTeX files to produce PDF files, suggesting pdflatex is the culprit. Perhaps, the problem is rather not with pdflatex, but with the configuration of pdflatex. My experience indicates that default configuration of most LaTeX distributions has already got the configuration right. However, my experience indicates that regardless I use pdflatex or the combination of latex, dvips, and ps2pdf, I have many occasions that not all fonts are embedded.

The issue is actually not with latex, but with figures generated by some third party tools. For instance, if you use Matlab to save figure as an eps file, for instance, the following Matlab script produces an eps file example_signal.eps showing a cosine signal.

num_periods = 10;

freq = 5;
sampling_interval = 1/100;
signal_length = num_periods * 1 / freq;
t = 1:sampling_interval:signal_length;
y = 10 * cos(2 * pi * freq * t + pi / 4);

plot(t, y);

set(gcf, 'PaperSize', [5 5*0.618]);
set(gcf, 'PaperPosition', [0 0 5 5*0.618]);
print('-depsc', 'example_signal');

Let us convert the eps file to a PDF file.

ps2pdf example_signal.eps
pdfcrop example_signal.pdf

Now let us verify if the resulting PDF file has had all fonts embedded,

pdffonts ./example_signal.pdf
name       type    encoding  emb sub uni object ID
---------- ------- --------- --- --- --- ---------
Helvetica  Type 1  Custom    no  no  no       8  0

The above shows that font Helvetica is not embedded. How do we make sure all fonts are embedded. You must include as the example shows, 5 switches in the ps2pdf command,

ps2pdf \
       -dPDFSETTINGS=/prepress \
       -dSubsetFonts=true \
       -dEmbedAllFonts=true \
       -dMaxSubsetPct=100 \
       -dCompatibilityLevel=1.4 ./example_signal.eps

pdffonts ./example_signal.pdf
name              type    encoding emb sub uni object ID
----------------- ------- -------- --- --- --- ---------
FHQQIQ+Helvetica  Type 1C Custom   yes yes no       8  0

We now see the font is embedded.

Note the following,
  • You must include the 5 switches in the ps2pdf command. If you miss one, fonts may not be all embedded. 
  • The command has no effect on PDF files, even though you can run ps2pdf against PDF files and no error or warning will be reported.

If you have a PDF file, but not its ps or eps file, you can use the steps below to convert the PDF file to a ps file and then convert the ps file back to a PDF file. The new PDF file will have all the fonts embedded, for instance,

pdf2ps example.pdf
ps2pdf \
       -dPDFSETTINGS=/prepress \
       -dSubsetFonts=true \
       -dEmbedAllFonts=true \
       -dMaxSubsetPct=100 \
       -dCompatibilityLevel=1.4 ./
That is all.

1 comment: