Skip to content

Instantly share code, notes, and snippets.

@bserem
Last active June 8, 2022 06:13
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 bserem/f3c410a724cd08b553a954b57ec67cdf to your computer and use it in GitHub Desktop.
Save bserem/f3c410a724cd08b553a954b57ec67cdf to your computer and use it in GitHub Desktop.
Batch compress PDF files like invoices (especially made for timologio by AADE that produces huge files)
#! /bin/bash
for f in *.pdf
do
fbname=$(basename "$f" .pdf)
fbname_safe="${fbname// /_}"
mv "$fbname".pdf $fbname_safe.temp.pdf
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$fbname_safe.pdf $fbname_safe.temp.pdf
# To also change PDF title (untested):
# gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$fbname_safe.pdf $fbname_safe.temp.pdf -c "[ /Title (My New Title) /DOCINFO pdfmark"
rm $fbname_safe.temp.pdf
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment