Cropping PDF Documents
Sometimes it’s useful to be able to crop all pages in a PDF document. ImageMagick1 can do this, but the command you’ll need is a little nuanced:
convert \
-density 300 \
-crop 2550x3616+0+0 \
+repage \
input.pdf \
-density 300 \
-compress jpeg \
-quality 75 \
output.pdf
Input File
-density 300
Specify the input density (given in dots per inch) of your PDF document. Without this, ImageMagick will default to 72 DPI, leading to a significant reduction in resolution. PDF documents created with a document scanner are typically 150 DPI or 300 DPI.
-crop 2550x3616+0+0
Select the crop, given as a geometry. For most common use-cases, the widthxheight+offsetX+offsetY format will suffice.
+repage
Ensure the page size of the output PDF document matches your crop. Without this, the page size of the output PDF document will be that of the input PDF document, leading to white borders.
input.pdf
The path of the input document.
Output File
-density 300
Ensure the output density matches the input density. Without this, your output PDF document will have different physical dimensions to your input PDF document.
-compress jpeg
Compress the images in the output PDF document as JPEG. Omitting this results in huge files.
-quality 75
Specify the JPEG output quality (on a scale of 0-100). I find 75 represents a good compromise between file size and quality.
output.pdf
The path of the output document.