C# PDF Viewer, Reader Library
How to insert, merge multiple PDF file pages into PDF file in C#.net, ASP.NET, MVC, Ajax, WinForms, WPF
Full featured C# source code to insert pages into PDF files using XDoc.PDF for .NET library. Free Online Trail Download.
- 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
- 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# add a blank page to specified pdf position
#region add a blank page to specified pdf position
internal static void insertBlankPageToPdf()
{
String filepath = @"";
String outPutFilePath = @"";
PDFDocument doc = new PDFDocument(filepath);
// Insert an empty page at 2 (previous to the third page).
doc.AddEmptyPage(2);
// Save the file.
doc.Save(outPutFilePath);
}
#endregion
C# add an existing pdf page to the specified pdf page position
#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
C# add list of existing pdf pages to the specified pdf page position
#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
Add a page (from a PDF file) to a PDFDocument object
// load the PDF file that provides the page object
String resFilePath = Program.RootPath + "\\" + "2.pdf";
PDFDocument resDoc = new PDFDocument(resFilePath);
// get the 1st page in the document
PDFPage page = (PDFPage)resDoc.GetPage(0);
// get PDFDocument object from a source file
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
// append selected page to the end of the PDFDocument
doc.AddPage(page);
// save the PDFDocument
String outputFilePath = Program.RootPath + "\\" + "Output.pdf";
doc.Save(outputFilePath);
Add pages (from a PDF file) to a PDFDocument object
String inputFilePath1 = Program.RootPath + "\\" + "1.pdf";
String inputFilePath2 = Program.RootPath + "\\" + "2.pdf";
String outPutFilePath = Program.RootPath + "\\" + "Output.pdf";
PDFDocument doc1 = new PDFDocument(inputFilePath1);
PDFDocument doc2 = new PDFDocument(inputFilePath2);
// get page 0, page 1 and page 3 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 };
// append selected pages to the second document
doc2.AddPages(pages);
// output the new document
doc2.Save(outPutFilePath);
Add an empty page to a PDF file
Output 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);
Overwrite the original 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);
Add empty pages to a PDF file with the specified start page index and count
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);
Create an empty PDF file
String outputFile = Program.RootPath + "\\" + "output.pdf";
// create a PDF file with three empty pages
PDFDocument.CreatePDFFile(outputFile, 3);
Create an empty PDF document object
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);