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.

Tue Apr 28, 2015 6:46 am

Is there a way to split one PDF file into multiple PDFs using a range of pages?

Page 1 - 10 --> DOC_1.pdf
Page 11-15 --> DOC_2.pdf
Page 16-89 --> DOC_3.pdf
...and so on


regs
Oliver

HMP
 
Posts: 6
Joined: Tue Aug 10, 2010 10:19 am

Wed Apr 29, 2015 7:23 am

Hello,

Thanks for your inquiry.
Please refer to the code below:
//Page 1 - 10 --> DOC_1.pdf
Code: Select all
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("d:\\spirePdf.pdf");
            PdfDocument pdf1 = new PdfDocument();
            PdfPageBase page = null;
            for (int i = 0; i < 10; i++)
            {
                page = pdf1.Pages.Add(pdf.Pages[i].Size, new Spire.Pdf.Graphics.PdfMargins(0));
                pdf.Pages[i].CreateTemplate().Draw(page, new System.Drawing.PointF(0, 0));
            }

            pdf1.SaveToFile("DOC_1.pdf");

//Page 11-15 --> DOC_2.pdf
Code: Select all
PdfDocument pdf2 = new PdfDocument();

            for (int i = 10; i < 15; i++)
            {
                page = pdf2.Pages.Add(pdf.Pages[i].Size, new Spire.Pdf.Graphics.PdfMargins(0));
                pdf.Pages[i].CreateTemplate().Draw(page, new System.Drawing.PointF(0, 0));
            }

            pdf2.SaveToFile("DOC_2.pdf");

For Page 16-89 --> DOC_3.pdf, you only have to change the parameter i.
and so on.
If I miss something or you have other problems, please feel free to contact us.

Sincerely,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Tue May 05, 2015 9:07 am

Hello,

Has your issue been resolved?
Thanks for your feedback.

Thanks,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Thu May 07, 2015 11:14 am

Perfekt, we tested the code, this will work for us.
I did not get any notification for your not to this post

HMP
 
Posts: 6
Joined: Tue Aug 10, 2010 10:19 am

Fri May 08, 2015 1:48 am

Hello,

Please feel free to contact us, if you have any questions or needs. We are here for help.

Sincerely,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.PDF