Created
June 19, 2016 23:53
-
-
Save BrunoGrandePhD/30e611b57920602866b27d27d700a396 to your computer and use it in GitHub Desktop.
Sometimes, the font is messed up on a printed version of a PDF file. It seems that this may be caused by the missing embedded fonts in the PDF file. The following shell function simplifies the process.
This file contains hidden or 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
# Ensure that fonts are embedded in a PDF file for correct printing | |
# Credit: http://stackoverflow.com/a/4234150 | |
function fixpdf { | |
# Print usage is no arguments are given | |
if [ "$#" -eq 0 ]; then | |
echo "Usage: fixpdf PDF_FILE [PDF_FILE ...]" | |
fi | |
# Check if ghostscript is installed | |
if ! type gs >/dev/null 2>&1; then | |
echo 'Error: ghostscript is either not installed or not in your PATH.' | |
echo 'Run `brew install gs` to install ghostscript.' | |
return 1 | |
fi | |
# Iterate over given PDF files | |
for file in "$@"; do | |
dir=$(dirname "$file") | |
base=$(basename "$file" .pdf) | |
gs \ | |
-sFONTPATH=/Library/Fonts:${HOME}/Library/Fonts \ | |
-o $dir/$base.fixed.pdf \ | |
-sDEVICE=pdfwrite \ | |
-dPDFSETTINGS=/prepress \ | |
"$file" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that
-sFONTPATH
is currently set to values that are tailored for OS X. Adjust accordingly.