How to Change Page Size of PDF using C#

This quick tutorial explains how to change page size of PDF using C#. It contains all the necessary details to establish the development environment, a sequence of steps that are to be followed to create the application and a runnable sample code that demonstrates the process to change size of PDF page using C# with the help of a few API calls only. This code can be used in any of the operating systems supporting the .NET framework like Windows, Linux, and macOS.

Steps to Change PDF Paper Size using C#

  1. Establish the environment to use Aspose.PDF for .NET to change page size
  2. load the source PDF file into the Document class object whose page dimensions are to be changed
  3. Get a reference to the collection of pages in the loaded PDF
  4. Get a reference to the target page from the collection whose size is to be updated
  5. Call the SetPageSize() method of the Page class and provide a new page size
  6. Save the resultant PDF file with an updated page size

These steps encompass the process to edit PDF page size using C# by sharing the resource that is required to test this feature. In the next step, we load the target PDF file, access its page collection, and then get then reference to the page whose size is to be updated. The page class contains a method SetPageSize() that is used to edit the page size by providing the page width and height

Code to Modify PDF Page Size using C#

This code demonstrates the process to change the size of a PDF page using C#. You have to calculate the width and height in points by multiplying the number of desired inches by 72 as Aspose.PDF uses the scale of 1 inch = 72 points. Suppose you want to set the page size to Envelop 10# which has a width of 4.13 inches and a height of 9.49 inches, hence you will multiply both numbers by 72 before passing it to the SetPageSize() method.

This article has taught us to change PDF page dimensions using C#. If you want to learn the process to add a watermark to a Pdf file, refer to the article on how to add watermark to PDF in C#.

 English