Tuesday, 6 May 2008

Embedding fonts in PDF with GhostScript

In a period in which I hardly have the time to breath, after having spent my birthday working, the only thing I have to annotate here is a very useful link to solve a bad problem of conference organisers: font embedding in pdfs.


In practice, the command to embed fonts is:
gs -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=letter -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile=figures/Mprime-new.pdf -f figures/Mprime.pdf
and it works perfectly.


Michael Head said...

This hasn't been working quite perfectly for me. It damages some of my figures (colored circles become filled dots) and it makes links that are marked non-visible visible.

So it's not quite perfect in all cases, and I'm still looking for a better way to embed them fonts!

Michael Head said...

Actually, here's a tweak that works a little better for me:

pdftops paper.pdf

Followed by:

ps2pdf -dSAFER -dNOPLATFONTS -sPAPERSIZE=letter -dEmbedAllFonts=true -dPDFSETTINGS=/prepress paper.ps paper.pdf

Zeppe said...

At a first glance, the main differences are the options -dPDFSETTINGS=/prepress instead of /printer that according to the documentation shouldn't do anything particularly differentb apart for changing the colour conversion strategy.

It is anyway worth trying to change that into /prepress in my command, because I guess the process should be equivalent for everything else (my command forces some thing, like the compatibility level on the pdf, that are guaranteed anyway by the /prepress and /printer settings).

Michael Head said...

/prepress is a red herring. I use it to ensure that any rasterized elements are at the highest resolution.

The critical difference is converting to postscript first. ghostscript's pdf to pdf translator doesn't seem to be able to perfectly interpret the PDF graphical bits correctly. pdftops is a tool from poppler (or xpdf) that does a correct job of rendering pdf as postscript. And of course ghostscript can handle postscript input like a champ.

Zeppe said...

ah right, I was confusing with pdf2ps, which is the gs tool and would just add an additional step to the chain.

Thanks for the hint, then, I'll bookmark this for next time I'll have hard times embedding fonts! :)

PypeBros said...

That's likely to save the day. Thanks ;)

Sushil Kumar said...

How we specify Font File or font name to substite for Missing font using Ghostscript.

Dorian MariƩ said...