4

I have many (around 1000) multiple-page PDFs for a program I am writing.

The problem is that many of them are inconsistent about page size, even within the same document at times. Does anyone know of a way I could programmatically go through the files and resize the pages to what I want? This can be in any language.

I can accomplish this in Adobe Acrobat Pro, but there are so many that would end up taking a long, long time. The only way I can get it to resize there is to add a background from a file, and then choosing the file i want to resize.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
  • I assume you can do that using any decent multi purpose PDF library. Are there any further criteria? Otherwise the question appears very broad. – mkl Jun 25 '13 at 21:15
  • The tricky bit is that the pages that are non-standard size are already cropped to specific content. So I can't just resize the crop boxes and reveal the other things. I need to take the cropped part of the page and put it at the top of a blank 6x9. Although I have figured out a way to do this in Adobe (as I said above), I just wanted to know if there was a way to do it programmatically. – Tyler Dougherty Jun 26 '13 at 13:00
  • You can put a clip path the size of the current crop box around the content and then resize any way you want. – mkl Jun 26 '13 at 18:09
  • @TylerDougherty As mkl indicates, this question is too broad for StackOverflow. You say you want to change the page size programmatically, but you don't tell us which programming language you want to use. Even if you know, you'll probably ask us to recommend a tool (and that is not allowed on SO). The fact that the pages don't have a standard size isn't tricky at all. A PDF library can retrieve the `/MediaBox` and `/CropBox` of every page. Some libraries will even allow you to redact the content so that the invisible parts are removed from the file. – Bruno Lowagie Apr 07 '15 at 10:29

3 Answers3

1

Generally, PDFtk is a good fit for this kind of problems. It will let you pull everything apart, and reorder/resize/modify pages on the command line.

Andrew Walker
  • 40,984
  • 8
  • 62
  • 84
  • My company decided to talk to the people who gave us the PDFs about getting better ones, since there were also some content problems, so it appears I may not have to go through these after all. But from the resources I have looked through in the last couple of days, this seems to be one of the simplest to accomplish close to what I was looking for. Thanks! – Tyler Dougherty Jun 26 '13 at 12:55
  • ***-1***. I downvoted this answer, because `pdftk` ***CANNOT*** (to my knowledge) resize pages. Should I be erring here, I'd be glad if you updated your answer with the exact command to do so, and I'll happily change my down- to an upvote. – Kurt Pfeifle Apr 07 '15 at 10:17
0

I had a similar problem and could easily solve it with PDF split and merge, a Java based toolkit for editing PDF files.

stefan.schwetschke
  • 8,862
  • 1
  • 26
  • 30
0

You can resize a PDF with a command line tool, Ghostscript.

Assuming you want to resize a PDF to 306x396 points (which would give you a quarter of a letter sized pages), do it like this:

gs                     \
 -o 306x396-points.pdf \
 -sDEVICE=pdfwrite     \
 -g3060x3960           \
 -dPDFFitPage          \
 -dUseCropBox          \
  input.pdf

Note that the -g.... dimensions are in pixels. Because Ghostscript internally computes with 720 PPI by default, these are increased by a factor of 10 as compared to the sizes in points.

For Windows, use gswin32c.exe or gswin64c.exe instead of gs.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345