9 How can I get Ghostscript to use embedded fonts in PDF?

Here is the command I use:

1 gs                         \
2   -o output.pdf            \
3   -dCompatibilityLevel=1.4 \
4   -dPDFSETTINGS=/screen    \
5   -sDEVICE=pdfwrite        \
6   -sOutputFile=output.pdf  \
7    input.pdf

I am using (trying anyway) to use Ghostscript to reduce my PDF file size. The command above looks like it works, it reduces file size greatly, but then several of the fields are garbled. As for as I can track it down, it’s doing font substitution. IE, the same text = same garbled text.

The fonts are embedded in the PDF when it gets to me. Additionally, I have tried to add all the fonts to the Fontmap.

Any ideas, Ideally I would like it to use the embedded fonts without me having to update the gs system fonts/edit fontmap, etc. I’m using Ubuntu 9.10 and the Fonts embedded are windows fonts, Arial/TimesNewRoman.

9.1 Answer

Embedding fonts retrospectivly which were not embedded in the original PDF does increase the file size, not decrease it.

However, there may still be a chance to reduce the overall file size by reducing the resolution of embedded images… depends on your preferences and needs.

You can try with variations of the following commandline. It will embed all fonts (even the “Base 14” ones), but embed required glyphs only (a “subset” of the original font), and also compress the fonts:

1 gs                          \
2    -o output.pdf            \
3    -dCompatibilityLevel=1.4 \
4    -dPDFSETTINGS=/screen    \
5    -dCompressFonts=true     \
6    -dSubsetFonts=true       \
7    -sDEVICE=pdfwrite        \
8    -c ".setpdfwrite <</NeverEmbed [ ]>> setdistillerparams" \
9    -f input.pdf

You will have noticed that I did use the -o output.pdf convention instead of -sOutputFile=output.pdf. I also didn’t include -dBATCH -dNOPAUSE in my command. The reason is that both methods are equivalent, since -o ... silently also sets -dBATCH -dNOPAUSE:

‘Traditional’ Ghostscript option:

1  -sOutputfile=output.pdf -dBATCH -dNOPAUSE

‘Modern’ Ghostscript options

1   -o output.pdf

However, the modern shortcut way of writing the command does not work for older Ghostscript versions.

If you look into reducing the file size of PDFs only and have now particularly compelling reason to set -dPDFSETTINGS=/screen, then the chapter “How can I convert a color PDF into grayscale?” may also be something to consider.