Skip to content

Instantly share code, notes, and snippets.

@qooxzuub
Created July 12, 2024 11:08
Show Gist options
  • Save qooxzuub/bd3c94759471985aa53bcfcfb59655f2 to your computer and use it in GitHub Desktop.
Save qooxzuub/bd3c94759471985aa53bcfcfb59655f2 to your computer and use it in GitHub Desktop.
Crop pdf using qpdf and jq
#!/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