Criado nova biblioteca de classes para os demais projetos referênciarem a classe "Fatura.cs" Atualização de bibliotecas.
31 lines
1.3 KiB
C#
31 lines
1.3 KiB
C#
// <copyright file="PDFSplitter.cs" company="Smart Energia">
|
|
// Copyright (c) Smart Energia. All rights reserved.
|
|
// </copyright>
|
|
|
|
namespace Faturas
|
|
{
|
|
using iText.Kernel.Pdf;
|
|
using iText.Kernel.Utils;
|
|
|
|
/// <summary>
|
|
/// Class for splitting PDF documents.
|
|
/// </summary>
|
|
public class PDFSplitter
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="PDFSplitter"/> class.
|
|
/// </summary>
|
|
/// <param name="pagina">The 1-based page number to extract; if null, the whole document is used.</param>
|
|
/// <param name="origem">Full path to the source PDF file to read.</param>
|
|
/// <param name="destino">Full path to the destination PDF file to create containing the extracted pages.</param>
|
|
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();
|
|
}
|
|
}
|
|
} |