Skip to content →

Embedding fonts into an existing PDF file (via an ugly hack)

Many academic conferences require that you submit PDF files with all fonts properly embedded. Making sure this happens for your LaTeX document using pdflatex is not difficult. However, some programs used to create figures don’t have an option to embed fonts, and when these figures are included in your LaTeX document, your final PDF ends up short a few fonts.

I’m sure there’s a more elegant way to solve this, but when I last faced it a few years ago, I hacked together an ugly shell script that converts the PDF to PS to EPS back to PDF again. I don’t recall why all these steps were necessary, but at the time this was the quickest thing I could find that worked:

#!/bin/bash
 
export GS_OPTIONS='-dEmbedAllFonts=true -dPDFSETTINGS=/printer'
cp $1 $1.old
pdftops $1 tmp.ps
ps2eps tmp.ps 
epstopdf tmp.eps 
mv tmp.pdf $1
rm tmp.ps tmp.eps

As you can see here, it successfully embeds the fonts in a pdf file, without increasing the file size too much. And each of the conversion steps should be lossless, so the final pdf looks exactly the same as the input:

jawolfe@[~/Projects/reports/11-ijcai/graphs]: pdffonts independent.pdf 
name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------
Helvetica                            Type 1            no  no  no       7  0
Symbol                               Type 1            no  no  no       8  0
jawolfe@[~/Projects/reports/11-ijcai/graphs]: ./fixfonts independent.pdf 
... (ignore the error messages)
jawolfe@[~/Projects/reports/11-ijcai/graphs]: ls -l
total 72
-rwxr--r--@ 1 jawolfe  admin   173 Apr 12 15:45 fixfonts*
-rw-r--r--  1 jawolfe  admin  9642 Apr 12 15:45 independent.pdf
-rw-r--r--  1 jawolfe  admin  4102 Apr 12 15:45 independent.pdf.old
jawolfe@[~/Projects/reports/11-ijcai/graphs]: pdffonts independent.pdf 
name                                 type              emb sub uni object ID
------------------------------------ ----------------- --- --- --- ---------
QHKFIS+Helvetica                     Type 1C           yes yes no       8  0
ONFWFL+Symbol                        Type 1C           yes yes no      10  0

Published in Uncategorized

One Comment

Leave a Reply to Matěj

Your email address will not be published. Required fields are marked *