View Full Version : Cropping Multiple Files

02-06-2010, 04:26 PM
Hi all,

I have a bunch of PDF ebooks, with stuff (text or images) in the borders which I want to remove before putting them onto my ereader. I had been opening them in Adobe Pro, and cropping them, but the text/images are still there when I open it on my ereader. So I am wondering if anyone knows of a good tool which can crop multiple files at once (the text/images are all in the exact same place on all the files), and either save them as a pdf, or as epub.


02-06-2010, 07:53 PM
The pdfmanipulate command line program that comes with calibre, used inside a batch file, can do this. If you need more info, post here but be sure to indicate which operating system you are using.

02-07-2010, 04:15 PM
More information as to how to make the batch file would be great. I am currently running windows 7 Pro.


02-07-2010, 06:59 PM
Unfortunately, I only have both Windows and calibre installed on my office computer, which I won't have access to until Tuesday. (Just linux at home!) However, I believe the process would be something like the following.

After installing calibre, paste the following into Notepad

for %%I in (*.pdf) do "C:\Program Files (x86)\Calibre2\pdfmanipulate.exe" crop -o "%%~nI-cropped.pdf" -x 100 -y 100 -w 100 -v 100 "%%I"

You'll probably want to make changes to this. First double check that the path to pdfmanipulate.exe is right, and that the case is right. If you're running 32 bit Win 7 rather than 64 bit, you might need to eliminate the (x86) part. Also, the numbers

-x 100 -y 100 -v 100 -w 100

indicate how many pixels to crop from the left, bottom, right and top, respectively. (I hope that's right... it might not be.) Change from 100 to whatever it needs to be. (Unfortunately I don't know the conversion from pixels to cm or inches offhand.) You might need to run it to test it a few times to get it right.

Save the file as something ending in .bat that you'll remember (batchcrop.bat or similar) in the folder where you have the PDFs you want to crop. Navigate to that folder in Windows Explorer or My Computer and double click the batch file. It'll then create cropped versions of all the PDFs in that folder. The new versions will be named filename-cropped.pdf and so on. (You can change that by editing what I have after -o above.)

That's my best guess at the moment. If I get a chance on Tuesday, I'll double check this, or maybe someone else who has access to both Windows and calibre can help.

Or you could ask in the calibre forum.

02-10-2010, 12:20 PM
OK, I was able to test the above now, and it works for me at least. Have you tried it?

02-15-2010, 02:49 PM

I just tried out the batch line you gave, and it worked really well. I used the following numbers to remove the unnecessary text/images, and also cut the unneeded whitespace down as well. It works really fast. Thanks again!

for %%I in (*.pdf) do "C:\Program Files\Calibre2\pdfmanipulate.exe" crop -o "%%~nI-cropped.pdf" -x 80 -y 70 -w 70 -v 80 "%%I"

02-15-2010, 03:08 PM
Is it a problem to post the command for Ubuntu?

02-15-2010, 05:45 PM
Not at all. It's similar, slightly simpler really. Open a terminal and navigate to the folder with your PDFs and type in:

for i in *.pdf ; do pdfmanipulate crop -o "${i%.pdf}-cropped.pdf" -x 80 -y 70 -w 70 -v 80 "$i" ; done

Change the values for -x -y -w and -v as desired.

02-15-2010, 06:05 PM
But actually, on Ubuntu, here's a cool alternative. Rather than setting the x, y, w and v values manually, you can have ghostscript analyze the pages and determine where they should be cropped:

for i in *.pdf ; do gs -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox "$i" 2> bounding ; pdfmanipulate crop -o "${i%.pdf}-cropped.pdf" -b bounding "$i"; done

I didn't suggest that for SpyKiller, since (s)he wanted to crop some non-empty parts of the page (decorative border), and this will leave them, but it's cool for other purposes.

Probably you can do that with Windows too, but I don't really have experience with ghostscript for Windows.

02-16-2010, 12:41 AM
Probably you can do that with Windows too, but I don't really have experience with ghostscript for Windows.

OK, it took awhile, since ghostscript works a bit different for Windows, but this seems to work.

Here's what you'd need to do.

1. Install both Calibre ( and Ghostscript (

2. Copy and paste the following in to Notepad.

for %%I in (*.pdf) do (
"C:\Program Files\gs\gs8.64\bin\gswin32c.exe" -dSAFER -dNOPAUSE -sDEVICE#bbox "%%I" 2> bounding
"C:\Program Files (x86)\Calibre2\pdfmanipulate.exe" crop -o "%%~nI-cropped.pdf" -b bounding "%%I"

3. Double check that the paths on your computer to pdfmanipulate.exe and gswin32c.exe are right. If you're using a 32 bit version of Windows, rather than a 64 bit version of Windows, you may need to change "C:\Progam Files (x86)\..." to just "C:\Program Files\". If you're using a newer or older version of ghost script, you may need to change "gs8.64" to something else, and so on.

4. Save the file as something ending in .bat, such as "multicrop.bat", and save it in the same directory as the PDFs you want to crop.

5. Open the folder in question in Windows Explorer or "My Computer" and double click on "multicrop[.bat]", and it should crop all the PDFs in that folder automatically.

(Please back-up all files before trying this and don't blame me too much if things go awry.)

Let me know how this works for you, and if the script needs tweaking.

02-17-2010, 01:30 PM
Thanks, frabjous! It works just fine!

05-20-2010, 05:23 PM

Ive tried this, it does not work for me. I have followed all the steps installed gost script and made the correct settings in the bat.

When i run the bat it starts working and goes thru all the pages but when it comes to the the end it just says GS> and stops.

The only new file that is created is file named bounding.

What do i do wrong?

Also, a question: does the pdf keep the links after cropped? Ive tried another croping method and by that all the links in the pdf (table of contents) was made inactive.

Thanks for your help!

10-01-2010, 12:25 AM
After four months, I'm answering your question! (Sorry for the delay, I just realized myself.)

I forgot the -dBATCH flag when posting the instructions for Windows. Try:

for %%I in (*.pdf) do (
"C:\Program Files\gs\gs9.00\bin\gswin32c.exe" -dSAFER -dNOPAUSE -dBATCH -sDEVICE#bbox "%%I" 2> bounding
"C:\Program Files\Calibre2\pdfmanipulate.exe" crop -o "%%~nI-cropped.pdf" -b bounding "%%I"

(Again, double check that the paths to the executables are right, and that it's the right version of ghostscript; I've updated it to 9.00.)

10-25-2012, 06:43 AM
I have been using frabjous code in a batch file under windows for some time and with great success (combining ghostcript and pdfmanipulate). I recently updated calibre and it came to my attention that pdfmanipulate is no longer maintained and has been removed from recent releases of calibre, e.g. versions 9 and up.

You can still get pdfmanipulate from there:

I downloaded the portable version and removed files that are not needed (I do use calibre, but I have a more up-to-date version installed in a separate directory). I haven't been able to figure out what a minimal configuration would be yet, but this you need: pdfmanipulate.exe, and things inside the two directories DLLs and resources. You probably only need a small number of files from these two directories (it would be nice to know which ones, so as to package pdfmanipulate with its dependencies and nothing else).

Unless there is a superior alternative to pdfmanipulate? I find it does a great job, that's why I was keen on staying with it, but I'm not tied to it either...

EDIT: I found that I could still crop pdfs by keeping just freetype.dll, python27.dll, pywintypes27.dll (all three dlls inside the DLLs directory), and just (inside the resources directory), together with pdfmanipulate.exe and It throws up harmless error messages, harmless as far as I can tell. The remains large at about 43MB, and presumably much can be removed from there too, but I haven't tried. So far I have reduced the directory from about 136MB to about 43MB. I would be surprised if it proved impossible to knock off about 40MB from that. But the process of removing files from and testing is tedious and my patience has run out.

10-29-2012, 01:59 AM
Unless there is a superior alternative to pdfmanipulate? I find it does a great job, that's why I was keen on staying with it, but I'm not tied to it either...
You might check the stickies in the PDF forum (, particularly Briss.

12-06-2012, 02:20 PM
You might check ... Briss.

Thanks willus, I've used briss before, but I need a fully automated setup, where the bounding boxes are automatically calculated. Ghostscript can be made to do it, with some scripts.

12-07-2012, 01:09 AM
Thanks willus, I've used briss before, but I need a fully automated setup, where the bounding boxes are automatically calculated. Ghostscript can be made to do it, with some scripts.
If you just want to crop each page of a PDF file to its bounding box, try k2pdfopt with these options:

-mode copy -n -t

This will copy the source file (-mode copy), keeping it in its native format (-n), but also trim each page to its bounding box (-t) as determined graphically by k2pdfopt. With k2pdfopt you can drop a folder full of PDF files onto the icon and it will batch process the entire folder. If you don't like how it names the output files, look into the -o option (command-line usage here ( No other scripts or programs needed. The only issue with the above command is that it will not size each output page to the trimmed region exactly. It will keep the aspect ratio the same as the original source page, but this is also adjustable with the -w and -h options.