Created
July 12, 2024 11:08
-
-
Save qooxzuub/bd3c94759471985aa53bcfcfb59655f2 to your computer and use it in GitHub Desktop.
Crop pdf using qpdf and jq
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
#!/usr/bin/env bash | |
if (( $# != 3 )); then | |
echo Usage: $0 in.pdf out.pdf '"x_bl,y_bl,x_tr,y_tr"' | |
exit 1 | |
fi | |
cmd='(..|objects|select(has("/MediaBox") or has("/CropBox")))' | |
cmd+='."/CropBox" = ['"$3"']' | |
tmp="$(tempfile)" | |
qpdf --json-output "$1" | jq "$cmd" > "$tmp" | |
qpdf --json-input "$tmp" "$2" && rm "$tmp" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment