Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
Can you please describe what kind of cropping you can do with Adobe Acrobat pro? Because I do not have it and can therefore not tell what you are looking for. –  xubuntix Apr 24 '12 at 8:50
    
In Adobe Acrobat Pro we can use the margin controls to crop the PDF. we can provide the value's for the top, bottom, right and left to crop –  Rakesh Apr 24 '12 at 8:56
add comment

4 Answers

Thanks for Rasmus, you can install pdfcrop from texlive-extra-utils package:

sudo apt-get install texlive-extra-utils

Then crop pdf files using pdf crop command as:

pdfcrop input.pdf output.pdf

use --help to see more amazing parameters like --margins

pdfcrop --margins 5 input.pdf output.pdf

which crop pdf with 5 pt from each side of page

share|improve this answer
add comment

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.

share|improve this answer
    
The first part of your answer is critique to another post and the remainder is GUI tools for which the OP isn't asking for. It may be useful in other questions, though. –  gertvdijk Jul 20 '13 at 12:04
add comment

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 bp, then run

pdfcrop --margins ’5 10 20 30’ input.pdf output.pdf

in terminal.

If you run only the command pdfcrop input, it will output a file titled input-crop.pdf with zero margins. I find this very handy when including pdf illustrations in documents.

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 something.sh. Open it with a text editor and insert the following:

#!/bin/bash

for FILE in ./*.pdf; do
  pdfcrop "${FILE}"
done

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 pdfcrop.

share|improve this answer
add comment

You could use a pypdf script from this page. But in the answer to this stackexchange question, there seem to be many options as well.

share|improve this answer
    
I am not able to get what the left top right bottom parameters are. are they points, inches, centimeters ? –  Rakesh Apr 24 '12 at 11:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.