// // Copyright (c) Smart Energia. All rights reserved. // namespace Faturas { using iText.Kernel.Pdf; using iText.Kernel.Utils; /// /// Class for splitting PDF documents. /// public class PDFSplitter { /// /// Initializes a new instance of the class. /// /// The 1-based page number to extract; if null, the whole document is used. /// Full path to the source PDF file to read. /// Full path to the destination PDF file to create containing the extracted pages. public PDFSplitter(int? pagina, string origem, string destino) { FileStream document = new (origem, FileMode.Open, FileAccess.Read, FileShare.Read); PdfDocument pdfDocument = new (new PdfReader(document)); var split = new CustomPdfSplitter(pdfDocument, pageRange => new PdfWriter(destino)); PdfDocument result = split.ExtractPageRange(new PageRange(pagina.ToString())); document.Close(); result.Close(); } } }