Skip to content

Instantly share code, notes, and snippets.

@ChuntaoLu
Created May 19, 2015 21:46
Show Gist options
  • Save ChuntaoLu/c4d0e053df326d2acc37 to your computer and use it in GitHub Desktop.
Save ChuntaoLu/c4d0e053df326d2acc37 to your computer and use it in GitHub Desktop.
Batch embed and subset pdf files in a directory
import os
import subprocess
import glob
# the shell command that embeds and subsets fonts in a pdf file
cmd = "gs -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=letter -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile={} -f {}"
for file_path in glob.glob(os.path.join('unembedded_dir_path', '*.pdf')):
target_path = os.path.join('embedded_dir_path', os.path.basename(file_path))
subprocess.call(cmd.format(target_path, file_path), shell=True)
subprocess.call(['pdffonts', target_path])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment