Super easy one but I can't seem to get this working
I have a PDF with 100 pages
I want it to break it into two documents
one with pages 1-50 and the other would be pages 51-100
how would I do that?
PdfDocument oldPdf = new PdfDocument();
oldPdf.LoadFromFile("old.pdf");
PdfDocument newPdf1 = new PdfDocument();
PdfDocument newPdf2 = new PdfDocument();
PdfPageBase page1;
PdfPageBase page2;
for (int i = 0; i < 100; i++)
{
if (i < 50)
{
//Add same size page for newPdf
page1 = newPdf1.Pages.Add(oldPdf.Pages[i].Size, new Spire.Pdf.Graphics.PdfMargins(0));
//Create template of the oldPdf page and draw into newPdf page
oldPdf.Pages[i].CreateTemplate().Draw(page1, new System.Drawing.PointF(0, 0));
}
else
{
//Add same size page for newPdf
page2 = newPdf2.Pages.Add(oldPdf.Pages[i].Size, new Spire.Pdf.Graphics.PdfMargins(0));
//Create template of the oldPdf page and draw into newPdf page
oldPdf.Pages[i].CreateTemplate().Draw(page2, new System.Drawing.PointF(0, 0));
}
}
String result1 = "new1.pdf";
String result2 = "new2.pdf";
//Save the document
newPdf1.SaveToFile(result1);
newPdf2.SaveToFile(result2);