I am looking for an open source command line tool to crop PDF file just like we can do in Adobe Acrobat Pro. I have tried PdfTk, ImageMagick, PyPDF, and GhostScript—all with no success so far.
I would suggest you take a look at PDFcrop.
If you wish to crop a pdf with left, top, right and bottom margins of 5, 10, 20, and 30 pt (points), then run
in terminal. To actually crop something away, use negative values in the argument for crop. For example,
crops 50 pts from the left, top, right, bottom (in this order).
If you run only the command
Cropping multiple files
Unfortunately, pdfcrop cannot crop multiple files at the time. It is however easy to write a script that will crop all pdfs in the folder the script is located in.
Create a new empty file, and call it
Save it, and close. Then right click the file, go to Properties > Permissions and check the field Allow executing file as program. Now close the dialog. Run the script by double clicking it and choosing Run in Terminal. And new, zero-margin cropped version of all pdfs with suffix -crop will now be printed in the folder. If you want margins or other things, you can of course just open the script and add arguments after
Thanks for Rasmus, you can install pdfcrop from texlive-extra-utils package:
Then crop pdf files using pdf crop command as:
which crop pdf with 5 pt from each side of page
You can also crop PDF files simply using Ghostscript. I have written a small script to simplify the process (inspired by this answer):
In order to determine the coordinates for cropping, I use
Now the maximum coordinates:
And finally, I run the script
I have no idea though, how the Ghostscript solution compares to
someone mentioned pdfcrop. It doesn't work for all PDFs. In fact, it doesn't work for most of the PDF books I have. The result is usually either uncut at all, or cut only the left margin. They may need some time to fix their bugs.
I wonder why folks in pdftk project did not add this to their arsenal. It seems so nature a need to them.
Although I also would love to use a commandline tool, the best available tools I tried are both GUI.
first is briss, at http://briss.sf.net which works fine with my openjdk-7 on Ubuntu.
the other is a Windows software: a-pdf http://www.a-pdf.com/page-crop/ and if you endeavor to try run it on WINE. It is more expensive, but has a lot more features - the ability to split books scanned with facing 2-pages is my favourite.