CommunityData:Embedding fonts in PDFs

From CommunityData

To check to see if a PDF is missing fonts, you can use the program pdffonts which comes in the Debian/Ubuntu package poppler-utils and the Arch Linux package poppler. If you run:

pdffonts foo.pdf

It should tell if you if the font is missing any fonts in that they will have rows with "no" in the column labled "emb".

This bash script will run a magical incantation of ghostscript which will embed fonts:

#!/bin/bash

for file in "$@"
do
    tmp_file=$(tempfile)
    output_file=$(echo $file |perl -p -e 's/.pdf$/-embedded_fonts.pdf/')

    # add fonts to each pdf
    gs -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
    -sPAPERSIZE=letter -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer \
    -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true \
    -dUseCIEColor=true \
    -dEmbedAllFonts=true \
    -sOutputFile="$tmp_file" -f "$file" > /dev/null

    mv "$tmp_file" "$output_file"
done


If you install this on your system (e.g., in bin/embed-fonts you can then just run it on a file like:

./embed-fonts foo.pdf

This will then create a new file called foo-embedded_fonts.pdf in the same directory as the original. You can verify that the fonts are embedded with pdffonts.