ExtractPages("E:\\Input\\PO_1_14101056-918476_20150911.pdf", "E:\\Output", 1, 2); public void ExtractPages(string sourcePdfPath, string outputPdfPath, int startPage, int endPage) { PdfReader reader = null; Document sourceDocument = null; PdfCopy pdfCopyProvider = null; PdfImportedPage importedPage = null; try { // Intialize a new PdfReader instance with the contents of the source Pdf file: reader = new PdfReader(sourcePdfPath); // For simplicity, I am assuming all the pages share the same size // and rotation as the first page: sourceDocument = new Document(reader.GetPageSizeWithRotation(startPage)); // Initialize an instance of the PdfCopyClass with the source // document and an output file stream: pdfCopyProvider = new PdfCopy(sourceDocument, new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create)); sourceDocument.Open(); // Walk the specified range and add the page copies to the output file: for (int i = startPage; i <= endPage; i++) { importedPage = pdfCopyProvider.GetImportedPage(reader, i); pdfCopyProvider.AddPage(importedPage); } sourceDocument.Close(); reader.Close(); } catch (Exception ex) { throw ex; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)