Add Pages in PDF with C#

Aspose.PDF for .NET API provides full flexibility to work with pages in a PDF document using C# or any other .NET language. It maintains all the pages of a PDF document in PageCollection that can be used to work with PDF pages. Aspose.PDF for .NET lets you insert a page to a PDF document at any location in the file as well as add pages to the end of a PDF file. This section shows how to add pages to a PDF using C#.

Add or Insert Page in a PDF File

Aspose.PDF for .NET lets you insert a page to a PDF document at any location in the file as well as add pages to the end of a PDF file.

Insert Empty Page in a PDF File at Desired Location

To insert an empty page in a PDF file:

  1. Create a Document class object with the input PDF file.
  2. Call the PageCollection collection’s Insert method with specified index.
  3. Save the output PDF using the Save method.

The following code snippet shows you how to insert a page in a PDF file.

In example above, we added empty page with default parameters. If you need to make page size the same as another page in document you shold add a few lines of code:

var page = pdfDocument.Pages.Insert(2);
//copy page parameters from page 1
page.ArtBox = pdfDocument.Pages[1].ArtBox;
page.BleedBox = pdfDocument.Pages[1].BleedBox;
page.CropBox = pdfDocument.Pages[1].CropBox;
page.MediaBox = pdfDocument.Pages[1].MediaBox;
page.TrimBox = pdfDocument.Pages[1].TrimBox;

Add an Empty Page at the End of a PDF File

Sometimes, you want to ensure that a document ends on an empty page. This topic explains how to insert an empty page at the end of the PDF document.

To insert an empty page at the end of a PDF file:

  1. Create a Document class object with the input PDF file.
  2. Call the PageCollection collection’s Add method, without any parameters.
  3. Save the output PDF using the Save method.

The following code snippet shows you how to insert an empty page at the end of a PDF file.