Created
May 19, 2015 21:46
-
-
Save ChuntaoLu/c4d0e053df326d2acc37 to your computer and use it in GitHub Desktop.
Batch embed and subset pdf files in a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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