Skip to content

Instantly share code, notes, and snippets.

@garaemon
Last active November 6, 2015 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garaemon/e7de9794a6c1a0e1147b to your computer and use it in GitHub Desktop.
Save garaemon/e7de9794a6c1a0e1147b to your computer and use it in GitHub Desktop.
compress pdf
COMP_COMMAND = "/default"
$(COMPRESSED_OUTPUT).pdf: $(OUTPUT).pdf
echo "Compressing pdf"
rm -f .pdfmarks
pdfinfo $(OUTPUT).pdf | sed -e 's/^ *//;s/ *$$//;s/ \{1,\}/ /g' -e 's/^/ \//' -e '/CreationDate/,$$d' -e 's/$$/)/' -e 's/: / (/' > .pdfmarks
sed -i '1s/^ /[/' .pdfmarks
sed -i '/:)\$$/d' .pdfmarks
echo " /DOCINFO pdfmark" >> .pdfmarks
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=${COMP_COMMAND} -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$(COMPRESSED_OUTPUT).pdf" "${OUTPUT}.pdf" .pdfmarks
rm .pdfmarks
notify-send "Compressed PDF"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment