PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.

Resize PDF pages

This sample demonstrates how to change the size of pages in the PDF file. For resizing the pages, a new page is created with the specified width and height and all the shapes of the original page are simply put on the new resized page which is then written to the disk as a PDF file.

const double scale = 0.5;

using (FileStream inputStream = new FileStream(@"..\..\../inputdocuments/PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read))
{
    // open the source document
    Document documentIn = new Document(inputStream);

    // create the target document
    Document documentOut = new Document();

    // enumerate the pages in the source document
    foreach (Page originalPage in documentIn.Pages)
    {
        // calculate a new size of the page
        double scaledWidth = originalPage.Width * scale;
        double scaledHeight = originalPage.Height * scale;

        // append a scaled version of the original page to the target document
        Page scaledPage = new Page(scaledWidth, scaledHeight);
        documentOut.Pages.Add(scaledPage);

        PageShape pageShape = new PageShape(originalPage, 0, 0, scaledPage.Width, scaledPage.Height);
        scaledPage.VisualOverlay.Add(pageShape);
    }

    // write the target document to disk
    using (FileStream outFile = new FileStream(@"..\..\output.pdf", FileMode.Create, FileAccess.Write))
    {
        documentOut.Write(outFile);
    }
}
const double scale = 0.5;

using (FileStream inputStream = new FileStream(@"..\..\../inputdocuments/PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read))
{
    // open the source document
    Document documentIn = new Document(inputStream);

    // create the target document
    Document documentOut = new Document();

    // enumerate the pages in the source document
    foreach (Page originalPage in documentIn.Pages)
    {
        // calculate a new size of the page
        double scaledWidth = originalPage.Width * scale;
        double scaledHeight = originalPage.Height * scale;

        // append a scaled version of the original page to the target document
        Page scaledPage = new Page(scaledWidth, scaledHeight);
        documentOut.Pages.Add(scaledPage);

        PageShape pageShape = new PageShape(originalPage, 0, 0, scaledPage.Width, scaledPage.Height);
        scaledPage.VisualOverlay.Add(pageShape);
    }

    // write the target document to disk
    using (FileStream outFile = new FileStream(@"..\..\output.pdf", FileMode.Create, FileAccess.Write))
    {
        documentOut.Write(outFile);
    }
}

The size of the original PDF page:

Original Pdf Size

The size of the resized PDF page:

Resized Pdf Page

Download PDFKit.NET 5.0
We will send you a download link

  • This field is for validation purposes and should be left unchanged.
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download

We have sent an email with a download link.