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.

Sat Dec 05, 2015 6:43 pm

Hello,

I have the following situation:
1 PDF with 1 page -> disclaimer, call it Y
1 PDF with different number of pages (1, 2, ... 10) -> invoice, call it X

I would like to insert the page from the first PDF (disclaimer) into the second PDF (invoice) at a specified index (index 1). I can only find a method to Append the page at the end of bigger PDF.
I did find a rearrange method, but I can't handle the possible different number of pages?

In short:
disclaimer: Y
invoice: X X X X X X
final doc: X Y X X X X X <- what to do to have this resulting doc?

Any easy method for this?

I thank you a lot in advance for your kind help. :)
Kind regards,

Punthoofd07
 
Posts: 4
Joined: Sat Dec 05, 2015 6:03 pm

Mon Dec 07, 2015 3:01 am

Hi,

Thanks for your inquiry.
Share sample code:
Code: Select all
PdfDocument doc1 = new PdfDocument();
            doc1.LoadFromFile("..\\..\\disclaimer.pdf");
            PdfDocument doc2 = new PdfDocument();
            doc2.LoadFromFile("..\\..\\invoice.pdf");

            PdfPageBase page = doc1.Pages[0];
            SizeF size = page.Size;

            PdfPageBase newPage = doc2.Pages.Insert(1, size);
            newPage.Canvas.DrawTemplate(page.CreateTemplate(),new PointF(0,0));

            doc2.SaveToFile(output);


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3047
Joined: Wed Jun 27, 2012 8:50 am

Mon Dec 07, 2015 9:16 pm

Hello,

Thanks for your input! But it doesn't work.
I have the following code now:
Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(filename);
PdfDocument voorwaarden = new PdfDocument();
voorwaarden.LoadFromFile(filename_voorwaarden);

/*****************************************/
/**** append disclaimer on page 2  *******/
/*****************************************/
PdfPageBase page = voorwaarden.Pages[0];
SizeF size = page.Size;

PdfPageBase newPage = doc.Pages.Insert(1, size);
newPage.Canvas.DrawTemplate(page.CreateTemplate(), new PointF(0, 0));

doc.SaveToFile("D:\\test.pdf");


If I have an invoice of 2 pages, it still adds the disclaimer (voorwaarden in Dutch) at the end of the document.
I really must oversee something...

Punthoofd07
 
Posts: 4
Joined: Sat Dec 05, 2015 6:03 pm

Tue Dec 08, 2015 2:08 am

Hi,

I tested your code and it worked, attached test files. I was using Spire.PDF Pack(Hot Fix) Version:3.5.143. Please try the version.

Code: Select all
 PdfDocument invoiceD = new PdfDocument();
             invoiceD.LoadFromFile(invoice);
             PdfDocument disclaimerD = new PdfDocument();
             disclaimerD.LoadFromFile(disclaimer);

             /*****************************************/
             /**** append disclaimer on page 2  *******/
             /*****************************************/
             PdfPageBase page = disclaimerD.Pages[0];
             SizeF size = page.Size;

             PdfPageBase newPage = invoiceD.Pages.Insert(1, size);
             newPage.Canvas.DrawTemplate(page.CreateTemplate(), new PointF(0, 0));

             invoiceD.SaveToFile(output);


If the issue still exists, please share your pdf files.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3047
Joined: Wed Jun 27, 2012 8:50 am

Tue Dec 08, 2015 5:58 pm

Hello,

I'm using FreeSpire.PDF v3.2. Found in the MS VS 2015 Nuget Package Manager. Should that work too?

Thanks for your response.

Punthoofd07
 
Posts: 4
Joined: Sat Dec 05, 2015 6:03 pm

Wed Dec 09, 2015 2:17 am

Hi,

Sorry that Free Spire.PDF v3.2 has some limitations on the function. Spire.PDF Pack(Hot Fix) Version:3.5.143 works fine in the case.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3047
Joined: Wed Jun 27, 2012 8:50 am

Wed Dec 09, 2015 5:57 pm

Except it isn't free or it shows a red text on top of the page? :|

Punthoofd07
 
Posts: 4
Joined: Sat Dec 05, 2015 6:03 pm

Thu Dec 10, 2015 1:47 am

Hi,

Please kindly notice that Spire.PDF Pack(Hot Fix) Version:3.5.143 is commercial edition. We can offer you a 1-month free license to remove the warning message . You could contact [email protected] to get a license file and have a better evalution on our products.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3047
Joined: Wed Jun 27, 2012 8:50 am

Wed Mar 11, 2026 10:48 am

Coding the logic for page reordering can be a bit of a headache, especially with complex document structures. While you're debugging your implementation, I've found https://www.thetoolapp.com/rearrange-pdf-pages/ really helpful for quickly verifying what the final output should look like or for fixing a small batch manually without having to re-run the whole script. It's a nice little shortcut to have in the toolkit.

Skylar31
 
Posts: 15
Joined: Mon Oct 13, 2025 8:37 am

Return to Spire.PDF

cron