Skip to content

Instantly share code, notes, and snippets.

@christopher-baek
Last active April 3, 2016 23:21
Show Gist options
  • Save christopher-baek/fdb085911c12e876a96d to your computer and use it in GitHub Desktop.
Save christopher-baek/fdb085911c12e876a96d to your computer and use it in GitHub Desktop.
PDF CLI Manipulation Examples

PDF CLI Manipulation Examples

# batch crop pdf
# - 72 points == 1 inch == 25.4 millimeters
#
# Example A4:
# 595 points width == 210 millimeters
# 842 points height == 297 millimeters
#
# Example:
# left edge: 24 points == 1/3 inch ~= 8.5 millimeters
# right edge: 36 points == 1/2 inch ~= 12.7 millimeters
# top edge: 48 points == 2/3 inch ~= 17.0 millimeters
# bottom edge: 72 points == 1 inch ~= 25.4 millimeters
gs -o cropped.pdf -sDEVICE=pdfwrite -c "[/CropBox [24 72 559 794] /PAGES pdfmark" -f uncropped-input.pdf
gs -o cropped.pdf -sDEVICE=pdfwrite -dDEVICEWIDTHPOINTS=595 -dDEVICEHEIGHTPOINTS=842 -dFIXEDMEDIA -c "24 72 translate 0 0 535 722 rectclip" -f uncropped-input.pdf
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile="${OUTPUT_FILE}" $@
gs -sDEVICE=pdfwrite -dSAFER -o "${INPUT_FILE%.pdf}.%03d.pdf" "${INPUT_FILE}"
# rotate all pages clockwise
pdftk in.pdf cat 1-endE output out.pdf
# rotate page 1 by 90 degrees clockwise
pdftk in.pdf cat 1E output out.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment