How to Insert a Page Into a PDF in C#

This short guide describes how to insert a page into a PDF in C#. It shares the necessary resources, a list of steps, and a runnable sample code for demonstrating the process to add PDF page in PDF file in C#. Different options to insert a page or multiple pages starting after a particular page in the output PDF file is also discussed.

Steps to Insert PDF Page Into PDF in C#

  1. Set the IDE to use Aspose.PDF for .NET for inserting a page in a PDF file
  2. Create an object of the PdfFileEditor class to insert a page
  3. Call the Insert() method in the PdfFileEditor class
  4. Provide the path to the input PDF file, destination index, source PDF file, pages range, and output file

These steps define the process of how to add a PDF page to another PDF in C#. The PdfFileEditor class is used for this purpose as it contains a lot of functions to add a PDF page to another PDF file. In this article we have used an overloaded method of insert function that takes the input PDF file name, the index of the page after which new pages are to be added, the template PDF file from which pages are to be added, the starting page index, the ending page index, and finally the destination file where original PDF file along with the inserted pages is to be saved.

Code to Add PDF Page to Another PDF in C#

This code sample demonstrates the process to add PDF page to PDF in C#. The PdfFileEditor class is used for inserting a page however it can also be used to add margins, page breaks, append pages, Concatenate PDF documents, and delete pages to name a few. After inserting a page, the resultant PDF file can also be saved to an HTTP response if required.

This article has taught us how to add page in PDF file in C#. If you want to learn the process to add attachments in a PDF file, refer to the article on how to attach a file to a PDF in C#.

 English