Skip to content

Instantly share code, notes, and snippets.

@shanmdphd
Last active September 11, 2017 05:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanmdphd/5883f2009afb7a4c390afe01b54d868e to your computer and use it in GitHub Desktop.
Save shanmdphd/5883f2009afb7a4c390afe01b54d868e to your computer and use it in GitHub Desktop.
Flatten PDFs with ghostscript (GS를 사용해서 PDF를 flattening할 수 있습니다. MacOS Sierra에서 테스트하였습니다.)
# http://zeroset.mnim.org/2015/01/07/flatten-pdfs-with-ghostscript/
# https://unix.stackexchange.com/questions/162922/is-there-a-way-to-flatten-a-pdf-image-from-the-command-line
# There should be `flat` sub-directory.
for file in *.pdf; do
gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite \
-sColorConversionStrategy=/LeaveColorUnchanged \
-dAutoFilterColorImages=true \
-dAutoFilterGrayImages=true \
-dDownsampleMonoImages=true \
-dDownsampleGrayImages=true \
-dDownsampleColorImages=true \
-sOutputFile="flat/flat-$file" "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment