How to repair a PDF file and embed missing fonts

Googlebot picture Googlebot · Oct 12, 2012 · Viewed 28.7k times · Source

I use pdftk to repair some failures in corrupted PDF files, but I faced another problem which is not fixed by pdftk (or at least I do not know how to do so).

I have PDF files with text based on TrueType fonts, but the fonts have not been embedded during PDF creation. Now I want to embed the required fonts to the existing files.

Is there a command-line tool (like pdftk) to embed missing fonts by providing path to TTF files?

Answer

Kurt Pfeifle picture Kurt Pfeifle · Oct 30, 2012

You can use Ghostscript to embed missing fonts. Run the command like this:

gs                                             \
  -o file-with-embedded-fonts.pdf              \
  -sDEVICE=pdfwrite                            \
  -dEmbedAllFonts=true                         \
  -sFONTPATH="/path/to/ttf;/other/path/to/ttf" \
   input-without-embedded-fonts.pdf

See also this answer: