Resize PDF content

Hi,
Suppose I have a PDF with content (generated by a third party). Need to resize all content to 90% to make room to add some mandatory text we need. Don’t want to resize the page size (currently A4). Is there a method that provides such functionality? Thanks!

Hi Gibbon,

Try this:

using (var document = PdfDocument.Load("input.pdf"))
{
    double scale = 0.9;
    var page = document.Pages[0];

    var elements = page.Content.Elements;
    var contentGroup = elements.Group(elements.First, elements.Last);
    contentGroup.Transform = new PdfMatrix(scale, 0, 0, scale, 0, 0);

    document.Save("output.pdf");
}

If you want to position the resized content to the center, then use this:

contentGroup.Transform = new PdfMatrix(scale, 0, 0, scale,
    page.Size.Width * (1 - scale) / 2,
    page.Size.Height * (1 - scale) / 2);

Regards,
Mario