Last active
December 5, 2024 21:40
-
-
Save phrz/7993bd2b0e3a6242509f52a45918a252 to your computer and use it in GitHub Desktop.
Compress PDFs for electronic faxing, where the attachment size limits are very small, by making them monochrome, pixelated, 200 DPI. Parallelized.
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
#!/bin/zsh | |
# brew install qpdf parallel imagemagick | |
set -e | |
tmpdir=$(mktemp -d) | |
trap 'rm -rf -- "$tmpdir"' EXIT | |
echo "Splitting PDF" | |
qpdf --warning-exit-0 --no-warn --split-pages=5 "$1" "$tmpdir/%d-out.pdf" # five page chunks | |
echo "Converting pages" | |
ls "$tmpdir"/*out.pdf | parallel --progress -j0 magick -monochrome -density 200 {} -compress Group4 {.}-comp.pdf | |
echo "Combining PDF" | |
qpdf --empty --pages "$tmpdir"/*-out-comp.pdf -- "${1%.*}_faxcompress.${1##*.}" | |
rm -rf -- "$tmpdir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment