i have a pdf which I need to down scale. The pdf is in A4 portrait mode, what I need is to shrink the content of the pdf to 5 % and put this into a new PDF also in size A4 a
Answer for PDFBox 2.0.*:
try (PDDocument doc = PDDocument.load(new File("...")))
{
for (int p = 0; p < doc.getNumberOfPages(); ++p)
{
PDPage page = doc.getPage(p);
try (PDPageContentStream cs = new PDPageContentStream(doc, page, AppendMode.PREPEND, true))
{
cs.saveGraphicsState();
cs.transform(Matrix.getScaleInstance(0.05f, 0.05f));
cs.saveGraphicsState();
}
try (PDPageContentStream cs = new PDPageContentStream(doc, page, AppendMode.APPEND, true))
{
cs.restoreGraphicsState();
cs.restoreGraphicsState();
}
}
doc.save(new File("...."));
}
You'll see something tiny in the bottom left.