Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Jul 09, 2020 7:17 pm

Hi

Can i check if there's a feature which can replace a page of the PDF from a page of another PDF file?

Thanks.

wonglau7479
 
Posts: 4
Joined: Sat Jul 04, 2020 8:49 am

Fri Jul 10, 2020 2:38 am

Hello,

Thanks for your inquiry.
Please refer to the following code to achieve your needs. Feel free to write back if there is any question.
Code: Select all
            PdfDocument pdfA = new PdfDocument();
            pdfA.LoadFromFile("FileA.pdf");

            PdfDocument pdfB = new PdfDocument();
            pdfB.LoadFromFile("FileB.pdf");

            //Replace the page 2 of File B with page 2 of File A
            //1. Remove the page 2 of File B
            pdfB.Pages.RemoveAt(1);
            //2. Insert a new page after page 1 of File B
            PdfPageBase pageB = pdfB.Pages.Insert(1, pdfB.Pages[0].Size);
            //3. Get the page 2 of File A
            PdfPageBase pageA = pdfA.Pages[1];
            //4. Draw template
            pageB.Canvas.DrawTemplate(pageA.CreateTemplate(), PointF.Empty);

            pdfB.SaveToFile("Result.pdf", FileFormat.PDF);

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Jul 10, 2020 7:05 am

Hi Rachel

Thanks for the prompt reply and yes it works well.

wonglau7479
 
Posts: 4
Joined: Sat Jul 04, 2020 8:49 am

Fri Jul 10, 2020 7:45 am

Hello,

Thanks for your feedback.
If you encounter any question related to our product in the future, just feel free to contact us.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF