Accusoft.PdfXpress7.Net
Split a PDF Document into Multiple PDFs

PDF Xpress™ supports splitting a source PDF document into multiple PDF documents using the InsertPages method.

C# Example
Copy Code
            // This code demonstrates splitting a source PDF into multiple PDFs
            Accusoft.PdfXpressSdk.PdfXpress pdfXpress1 = null;
            Document document = null;
            Document doc_new = null;
            InsertPagesOptions io = null;
            OpenOptions oo = null;
            PageList pageList = null;
            PageRange pageRange = null;
            Accusoft.PdfXpressSdk.SaveOptions so = null;
            try
            {
                pdfXpress1 = new PdfXpress();
                pdfXpress1.Initialize(null, null);
                oo = new OpenOptions();
                oo.Filename = "C:\\multipage.pdf";
                document = new Document(pdfXpress1, oo);
                io = new InsertPagesOptions();
                io.SourceDocument = document;
                int pageCount = document.PageCount;
                pageList = new PageList();
                pageRange = new PageRange();
                pageList.Add(pageRange);
                io.PageList = pageList;
                so = new SaveOptions();
                //Loop through each page and save it into a new file each time
                for (int a = 0; a < pageCount; a++)
                {
                    io.InsertAtPageNumber = 0;
                    pageRange.StartPageNumber = a;
                    pageRange.PageCount = 1;
                    doc_new = new Document(pdfXpress1);
                    doc_new.InsertPages(io);
                    so.Filename = "C:\\split" + a + ".pdf";
                    doc_new.Save(so);
                }
            }
            catch (System.Exception)
            {
            }
            finally
            {
                if (null != document)
                {
                    document.Dispose();
                }
                if (null != doc_new)
                {
                    doc_new.Dispose();
                }
                if (null != pdfXpress1)
                {
                    pdfXpress1.Dispose();
                }
            }
See Also

 

 


©2018. Accusoft Corporation. All Rights Reserved.

Send Feedback