C# PDF Reader Library
How to add pages from other PDF file into a new created PDF or an existing PDF file in C# ASP.NET
Full featured C# source code to insert pages into PDF files using XDoc.PDF for .NET library. Free Online Trail Download.
In this tutorial, you learn how to add, insert PDF pages programmatically using C# in .NET WinForms, WPF, ASP.NET MVC web applications.
- Add blank pages
- Insert an existing PDF page
- Insert list of pages
- Insert pages from one PDF document to another PDF file
How to add, insert PDF pages programmatically using C#
- Best C#.NET PDF SDK for inserting PDF pages in Visual Studio .NET framework
- Free .NET evaluation library for adding pages to adobe PDF in both .NET WinForms application and ASPX webpage
- Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
- Besides adding new page to PDF, C# PDF library also includes
how to show page numbers in pdf using c#,
c# resize pdf page,
how to add header and footer in pdf using c#,
c# read pdf page,
c# pdf crop,
c# rotate pdf document.
- C#.NET source code for inserting a single one page or multiple pages to PDF document in .NET console application
- Able to create a blank PDF page in both web server-side application
- C#.NET users can insert a PDF page from a supported file format
- Ability to add PDF page number in preview
- Offer PDF page break inserting function
C#.NET PDF document editor library control, RasterEdge XDoc.PDF, offers easy & mature APIs for developers to add &
insert an (empty) page into an existing PDF document file. Besides, this PDF document page inserting library control toolkit allows developers to
specify where they want to insert (blank) PDF document page (before the first page or after the last page or after any desired page of current PDF document)
using C# .NET class code.
This C# .NET PDF document page inserting & adding component from RasterEdge is written in managed C# code and designed particularly for .NET class applications.
Thus, using this PDF document page manipulating and processing control SDK, you can create & add new PDF page(s) to current target PDF document in
both web server-side application and Windows Forms project using a few lines of simple C# code.
Apart from the ability to inserting a new PDF page into existing PDF document file, RasterEdge C# .NET PDF document page processing and
editing control toolkit also owns other advanced PDF document page manipulating functions.
RasterEdge offers detailed guidances for each of those page processing functions, such as
how to merge PDF document files by C# code, how to rotate PDF document page,
how to delete PDF page using C# .NET,
how to reorganize PDF document pages
and
how to split PDF document in C# .NET class application.
By using reliable APIs, C# programmers are capable of adding and inserting (empty) PDF page or pages from various file formats, such as PDF, Tiff, Word,
Excel, PowerPoint, Bmp, Jpeg, Png, Gif, and so on. Some C# demos are provided for your reference.
C# insert a blank page to specified pdf position
Use method PDFDocument.AddEmptyPage() to insert blank pages into PDF file in C#.
The following C# source code will show how to insert an empty page with page size A4 (8.27 in. x 11.69 in.) previous to the third page.
String filepath = @"";
String outPutFilePath = @"";
PDFDocument doc = new PDFDocument(filepath);
// Insert an empty page at 2 (previous to the third page).
doc.AddEmptyPage(2, PaperSize.A4);
// Save the file.
doc.Save(outPutFilePath);
Add an empty page to a PDF file
The following C# source code will show how to insert an empty page before the first page and save to a new file.
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFilePath = Program.RootPath + "\\" + "Output.pdf";
int pageIndex = 0;
// insert an empty page before the first page
PDFDocument.AddEmptyPage(inputFilePath, pageIndex, outputFilePath);
Add multiple empty pages to a PDF file in C#
You can also insert multiple blank pages to an existing PDF file in C#.
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFilePath = Program.RootPath + "\\" + "Output.pdf";
int startPageIndex = 1;
int numberOfPages = 5;
// insert 5 empty pages after first page
PDFDocument.AddEmptyPages(inputFilePath, startPageIndex, numberOfPages);
How to insert a page from another PDF file in C#
You can easily get a page from one PDF file and insert it to another PDF document.
The following C# sample codes show how to insert a page from other PDF file.
- Create two PDFDocument objects with pdf files loaded
- Get PDFPage object from the first page of the first PDF document
- Insert the PDF page object into second PDF document
- Save the second PDF file
#region add an existing pdf page to the specified pdf page position
internal static void insertExistingPageToPdf()
{
String inputFilePath1 = @"C:\1.pdf";
String inputFilePath2 = @"C:\2.pdf";
String outPutFilePath = @"C:\Output.pdf";
PDFDocument doc1 = new PDFDocument(inputFilePath1);
PDFDocument doc2 = new PDFDocument(inputFilePath2);
// Get a page from the first document.
PDFPage page = (PDFPage)doc1.GetPage(0);
// Specify a position for inserting the selected page.
int pageIndex = 2;
// Insert the page to the second document at specified position.
doc2.InsertPage(page, pageIndex);
// Output the new document.
doc2.Save(outPutFilePath);
}
#endregion
How to insert list of pages from other file in C#
You can also get list of PDF pages from one or more files, and insert them into another PDF document using C#.
The following C# sample codes show how to insert multiple pages from other PDF file.
- Create two PDFDocument objects with each pdf document loaded
- Get three PDFPage objects from the first PDF file (located on the first, second, third of the document)
- Insert the three PDF page objects into second PDF document
- Save the second PDF file
#region add list of existing pdf pages to the specified pdf page position
internal static void insertExsitingPagesToPdf()
{
String inputFilePath1 = @"C:\1.pdf";
String inputFilePath2 = @"C:\2.pdf";
String outPutFilePath = @"C:\Output.pdf";
PDFDocument doc1 = new PDFDocument(inputFilePath1);
PDFDocument doc2 = new PDFDocument(inputFilePath2);
// Get page 0, page 1 and page 2 from the first document.
PDFPage page0 = (PDFPage)doc1.GetPage(0);
PDFPage page1 = (PDFPage)doc1.GetPage(1);
PDFPage page2 = (PDFPage)doc1.GetPage(2);
PDFPage[] pages = new PDFPage[3] { page0, page1, page2 };
// Specify a position for inserting the selected pages.
int pageIndex = 1;
// Insert the pages to the second document at specified position.
doc2.InsertPages(pages, pageIndex);
// Output the new document.
doc2.Save(outPutFilePath);
}
#endregion
Create a new PDF file with one empty page in C#
The following C# source codes will show how to create a new PDF file with one or more empty pages inside.
String outputFile = Program.RootPath + "\\" + "output.pdf";
// create a PDF file with three empty pages
PDFDocument.CreatePDFFile(outputFile, 3);
Create an empty PDF document object with 2 blank pages in C#
String outputFile = Program.RootPath + "\\" + "output.pdf";
// Create a PDF Document object with 2 blank pages
PDFDocument doc = PDFDocument.Create(2);
// Save the new created PDF document into file
doc.Save(outputFile);