views:

138

answers:

2

I'm often interested in cropping pdfs,* and one tool I use to do this is Heiko Oberdiek's script pdfcrop.pl. I would like to try pdfcrop2, a fork of pdfcrop.pl, but the Google Code page (the only source of information I've found about pdfcrop2) only has patches to an old version of pdfcrop.pl, which I can't find a copy of. Does anybody know where I can either get a copy of pdfcrop2 or version 1.5 of pdfcrop.pl?

*In addition to getting ahold of a working copy of pdfcrop2, I'd be happy to learn about any other tools (preferably Free) that can be used to crop pdfs. pdftk is fantastic for doing just about anything other than cropping.

+2  A: 

Edit: The full pdfcrop2 is available in their svn repo: http://code.google.com/p/pdfcrop2/source/browse/trunk/pdfcrop.pl

Original answer.

pdfcrop 1.5 was shipped with debian and ubuntu; looking in the orig.tar.gz for the texlive-bin source package which you can grab from a nearby Debian mirror should work.

I've posted a copy at http://pastebin.com/m4c94ec08 temporarily for you...

Stobor
Thanks Stobor! I can't believe I didn't notice the svn repo on the google code page. I couldn't check out the repo you posted, but this one worked: `svn checkout pdfcrop2.googlecode.com/svn/trunk pdfcrop2-read-only`. As for pdfcrop 1.5, it turns out that it's also included in the package `texlive-extra-utils` which was easier for me to grab (I'm running ubuntu and I couldn't find a `texlive-bin` package among my current sources).
Anton Geraschenko
@Anton: yeah, I pointed to the web-svn viewer, rather than to the repo itself. Glad you found the bits and pieces.
Stobor
+1  A: 

I have played a bit with pyPdf for setting page boxes. Below is some test code to generate a PDF with just the even pages, setting the media box and crop box top right to the same as the first page which could be a starting point for something more useful.

#!/usr/bin/python

from pyPdf import PdfFileWriter, PdfFileReader
from pdfsave import pdfSave
import sys

def pdfSetBoxes(input, output, mediaBox, cropBox):
    numPages = input.getNumPages()
    for pageNum in range(1,numPages, 2):
        page = input.getPage(pageNum)
        page.mediaBox.upperRight = mediaBox
        page.cropBox.upperRight = cropBox
        output.addPage(page)

input = PdfFileReader(file(sys.argv[1], "rb"))
output = PdfFileWriter()

page0 = input.getPage(0)
mb = page0.mediaBox.getUpperRight()
cb = page0.cropBox.getUpperRight()

pdfSetBoxes(input, output, mb, cb)
pdfSave(output, sys.argv[2])
danio
The beginnings of another pyPdf based cropping script can be found here: http://www.mobileread.com/forums/showthread.php?t=25565
Anton Geraschenko
@Anton - that looks good - should be something to use in future...
danio