XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to HTML5 Viewer & Editor PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Page: Replace PDF Pages
  |  
Home ›› XDoc.PDF ›› C# PDF: Replace PDF Pages

How to replace PDF document pages using XDoc.PDF for .NET library in C#, ASP.NET, Winforms, WPF, Azure


An Excellent PDF Control Allows C# Users to Replace the Original PDF Page with New PDF Page from Another PDF File in C#.NET




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 WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint


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 by another pdf page


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




        #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




C# replace list of consecutive pages by another list of pdf pages





        #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 1st page 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 3rd page 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




.NET Class Namespace Required



Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;





public override void UpdatePage(BasePage newPage, int pageIdx)

Description:
     Replace the specified page with new page.

Parameters:

Return:
     Error code, 0 if success.



public int UpdatePages(BasePage[] newPages, int[] pagesIdx)

Description:
     Delete consecutive pages from the input PDF file starting at specified position.

Parameters:

Return:
     Error code, 0 if success.