This is sample of code to extract pages from pdf file to new file
public static void Main(string[] args) { try { string sourcePath = args[0]; string outputPath = args[1]; PdfReader reader = new PdfReader(sourcePath); Document document = new Document(reader.GetPageSizeWithRotation(1)); PdfCopy copier = new PdfCopy(document, new FileStream(outputPath, FileMode.Create)); //PdfCopy copier = PdfCopy.GetInstance(document, new FileStream(args[1], FileMode.Create)); int startpage = int.Parse(args[2]); int endpage = int.Parse(args[3]); document.Open(); for (int pageCounter = startpage; pageCounter <= endpage && pageCounter < reader.NumberOfPages + 1; pageCounter++) { PdfImportedPage page = copier.GetImportedPage(reader, pageCounter); //byte[] page = reader.GetPageContent(pageCounter); copier.AddPage(page); } document.Close(); reader.Close(); } catch (DocumentException de) { System.Console.Error.WriteLine(de.Message); } catch (IOException ioe) { System.Console.Error.WriteLine(ioe.Message); } } |
No comments:
Post a Comment