1

How can I make the page larger in the way that the text/images will stretch according to the new size? I only found ways to scale down but not scale up... any idea?

Thanks in advance!!!

coral
  • 181
  • 1
  • 1
  • 12

1 Answers1

1

There are two conceptional options:

  1. For each page enlarge MediaBox and CropBox, prepend current transformation matrix scaling operation to the page content stream or array of streams, and update annotation positions and sizes.

  2. For each page set the property UserUnit to a value > 1.

The second option can e.g. be implemented like this using PDFBox and a stretch factor of 1.7:

PDDocument document = PDDocument.load(SOURCE);

for (PDPage page : document.getPages()) {
    page.getCOSObject().setFloat("UserUnit", 1.7f);
}

document.save(TARGET);

(The second option obviously is much easier to implement than the first one. Feature incomplete PDF viewers might ignore this value, though. If you need to support such incomplete viewers, you probably have to go for the first option.)

mkl
  • 90,588
  • 15
  • 125
  • 265
  • Thank you!! I tried the second option and it solved it!! :) where did you find the documentation of this attribute? – coral Apr 10 '18 at 13:09
  • @coral *"where did you find the documentation of this attribute"* - It's in the PDF format specification, ISO 32000, both in part 1 and part 2. Adobe has made a copy of part 1 publicly available [here](https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf). – mkl Apr 10 '18 at 13:37