C# PDF Page Parser Library
How to replace PDF pages using C#.net.
An Excellent PDF Control Allows C# Users to Replace the Original PDF Page with New PDF Page from Another PDF File in C#.NET
In this C# tutorial, you will learn how to find, replace PDF pages programmatically using C#
- Replace a PDF page with another PDF page
- Replace a list of continuous PDF pages with other PDF pages
How to replace PDF pages programmatically using C#
- Professional PDF SDK for Visual Studio .NET, which able to replace PDF page in C#.NET class
- Advanced PDF edit control and component for replacing PDF pages in both C#.NET WinForms
- Free online sample code for quick evaluation in Visual C#.NET framework for PDF page replacing
- Support .NET Core, ASP.NET .NET Core, MVC, .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
- Powerful PDF pages editing C# library:
c# pdf extract pages,
how to add header and footer in pdf using c#,
c# pdf page size,
c# pdf crop,
page number total pages in c#,
c# pdf add background.
- Easy to replace PDF pages online in browser in ASP.NET web project
- Support to replace a PDF page with another PDF file page in .NET framework
- Support to save multiple PDF pages to anther PDF document by replacing
You can replace an entire PDF page with another PDF page from another PDF file. All information, data on the original page are removed,
including text, images, interactive elements, such as links and bookmarks.
C# replace a single pdf page
You can easily replace an entire PDF page with another PDF page in C#. Below are the steps and C# sample code to replace a PDF page using XDoc.PDF for .NET library.
- Create a resource PDFDocument object with a PDF file loaded
- Get the resource PDFPage object (1st page) of the pdf file
- Create a PDFDocument object to replace a page
- Replace the pdf object 3rd page with the resource page
- Save the PDF file
#region replace a single pdf page by another pdf page
internal static void repaceSinglePage()
{
// load the PDF file that provides the page object
String resFilePath = @"C:\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 = @"C:\1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
// replace the 3rd page by the PDFPage object
int pageIndex = 2;
doc.UpdatePage(page, pageIndex);
// save the PDFDocument
String outputFilePath = @"C:\Output.pdf";
doc.Save(outputFilePath);
}
#endregion
How to replace list of consecutive pages in C#
You can also replace a list of consecutive PDF pages in C#. Below are the steps and C# sample code to replace a list of continuous PDF pages.
- Create a resource PDFDocument object with a PDF file loaded
- Get the three resource PDFPage objects of the pdf file
- Create a PDFDocument object to replace pages
- Replace the pdf object 6th, 7th, 8th pages with the resource pages
- Save the PDF file
#region replace pdf pages by another pdf pages
internal static void repacePages()
{
// load the PDF file that provides the page object
String resFilePath = @"C:\2.pdf";
PDFDocument resDoc = new PDFDocument(resFilePath);
// get the three pages in the document
PDFPage page1 = (PDFPage)resDoc.GetPage(0);
PDFPage page2 = (PDFPage)resDoc.GetPage(1);
PDFPage page3 = (PDFPage)resDoc.GetPage(2);
List<BasePage> pages = new List<BasePage>();
pages.Add(page1);
pages.Add(page2);
pages.Add(page3);
// get PDFDocument object from a source file
String inputFilePath = @"C:\1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
// replace the 6th, 7th, 8th pages by the PDFPage object
int[] pageIndexes = new int[] { 5,6,7 };
doc.UpdatePages(pages.ToArray(), pageIndexes);
// save the PDFDocument
String outputFilePath = @"C:\Output.pdf";
doc.Save(outputFilePath);
}
#endregion
Replace a page (in a PDFDocument object) by a page 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);
// replace the 3rd page by the PDFPage object
int pageIndex = 2;
doc.UpdatePage(page, pageIndex);
// save the PDFDocument
String outputFilePath = Program.RootPath + "\\" + "Output.pdf";
doc.Save(outputFilePath);