Add Pages to PDF via C#

Insert pages to PDF document programmatically using Aspose.PDF for .NET Library

How to Add pages to PDF Using C#

In order to insert page in PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for net platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF

Insert Page to PDF via C#


You need Aspose.PDF for .NET to try the code in your environment.

  1. Create a Document 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.

Insert New Page to PDF


    // Open document
    Document pdfDocument1 = new Document(dataDir + "InsertEmptyPage.pdf");

    // Insert a empty page in a PDF
    pdfDocument1.Pages.Insert(2);
    dataDir = dataDir + "InsertEmptyPage_out.pdf";
    // Save output file
    pdfDocument1.Save(dataDir);