Pdf Split |
Select.Pdf can be used to split an existing pdf document into several pdf documents or extract only certain pages from a pdf document and create a new pdf document only with them.
To achive this task, the pdf file needs to be loaded into a PdfDocument object. The following sample code shows how to load an existing file from the disk:
Another important property that will be used by the pdf split feature is the Pages property of the PdfDocument object. Using this property, the full collection of pdf pages from the pdf document can be accessed:
This sample code shows how to create a new pdf document containing only pages 2 and 3 from the original pdf document.
// the initial file string file1 = Server.MapPath("~/files/doc.pdf"); // load the pdf document PdfDocument doc1 = new PdfDocument(file1); // create a new pdf document PdfDocument doc = new PdfDocument(); // add 2 pages to the new document if (doc1.Pages.Count > 2) { doc.AddPage(doc1.Pages[1]); doc.AddPage(doc1.Pages[2]); } // save pdf document doc.Save(Response, false, "Sample.pdf"); // close pdf document doc.Close(); // close the original pdf document doc1.Close();