v25.10
Nuevo plugin PDF Extractor
- Class PdfExtractor: contiene todas las funciones de los plugins: TextExtractor, ImageExtractor, FormExporter.
- Class TextExtractor: será eliminado pronto, use PdfExtractor.
- Class ImageExtractor: será eliminado pronto, use PdfExtractor.
- Class FormExporter: será eliminado pronto, use PdfExtractor.
- Class TextExtractorOptions: renombrado a Class ExtractTextOptions.
- Class ImageExtractorOptions: renombrado a Class ExtractImagesOptions.
- Class FormExportToDsvOptions: renombrado a Class ExtractFormDataToDsvOptions.
- Consulte The New Plugin Architecture.
Ejemplo de uso:
El ejemplo muestra cómo extraer el contenido de texto de un documento PDF.
// Create ExtractTextOptions object to set instructions
var options = new ExtractTextOptions();
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Perform the process
var results = PdfExtractor.ExtractText(options);
// Get the extracted text from the ResultContainer object
var textExtracted = results.ResultCollection[0].ToString();Ejemplo de uso:
El ejemplo muestra cómo extraer el contenido de texto de un documento PDF con TextFormattingMode.
// Create ExtractTextOptions object to set TextFormattingMode
var options = new ExtractTextOptions(TextFormattingMode.Pure);
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Perform the process
var results = PdfExtractor.ExtractText(options);
// Get the extracted text from the ResultContainer object
var textExtracted = results.ResultCollection[0].ToString();Ejemplo de uso:
El ejemplo muestra cómo extraer imágenes de un documento PDF.
// Create ExtractImagesOptions to set instructions
var options = new ExtractImagesOptions();
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryDataSource("path_to_results_directory"));
// Perform the process
var results = PdfExtractor.ExtractImages(options);
// Get path to image result
var imageExtracted = results.ResultCollection[0].ToFile();Ejemplo de uso:
El ejemplo muestra cómo exportar los valores de formulario a un archivo CSV.
// Create ExtractFormDataToDsvOptions object to set instructions
var options = new ExtractFormDataToDsvOptions(',', true);
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_csv_file.csv"));
// Perform the process
PdfExtractor.ExtractFormData(options);Nuevo plugin PDF Manager
- Class PdfManager: contiene todas las funciones de los plugins: Merger, Optimizer, Splitter, TableGenerator, TocGenerator.
- Class Merger: será eliminado pronto.
- Class Optimizer: será eliminado pronto, use PdfManager.
- Class Splitter: será eliminado pronto, use PdfManager.
- Class TableGenerator: será eliminado pronto, use PdfManager.
- Class TocGenerator: será eliminado pronto, use PdfManager.
- Consulte The New Plugin Architecture.
Ejemplo de uso:
El ejemplo muestra cómo combinar dos documentos PDF.
// Create MergeOptions object to set instructions
var options = new MergeOptions();
// Add input file paths
options.AddInput(new FileDataSource("path_to_your_pdf_file_1.pdf"));
options.AddInput(new FileDataSource("path_to_your_pdf_file_2.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Merge(options);Ejemplo de uso:
El ejemplo muestra cómo dividir un documento PDF.
// Create SplitOptions object to set instructions
var options = new SplitOptions();
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file paths
options.AddOutput(new FileDataSource("path_to_result_pdf_file_1.pdf"));
options.AddOutput(new FileDataSource("path_to_result_pdf_file_2.pdf"));
// Perform the process
PdfManager.Split(options);Ejemplo de uso:
El ejemplo muestra cómo optimizar un documento PDF.
// Create OptimizeOptions object to set instructions
var options = new OptimizeOptions();
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Optimize(options);Ejemplo de uso:
El ejemplo muestra cómo rotar un documento PDF.
// Create RotateOptions object to set instructions
var options = new RotateOptions();
// Set new Rotation
options.Rotation = Rotation.On90;
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Rotate(options);Ejemplo de uso:
El ejemplo muestra cómo cambiar el tamaño de página de un documento PDF.
// Create ResizeOptions object to set instructions
var options = new ResizeOptions();
// Set new PageSize
options.PageSize = PageSize.A3;
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Resize(options);Ejemplo de uso:
El ejemplo muestra cómo comprimir un documento PDF.
// Create CompressOptions object to set instructions
var options = new CompressOptions();
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Compress(options);Ejemplo de uso:
El ejemplo muestra cómo añadir una tabla a un archivo PDF.
// Configure table options
var options = new TableOptions();
options.InsertPageBefore(1)
.AddTable()
.AddRow()
.AddCell().AddParagraph("Name")
.AddCell().AddParagraph("Age")
.AddRow()
.AddCell().AddParagraph("Bob")
.AddCell().AddParagraph("12")
.AddRow()
.AddCell().AddParagraph("Sam")
.AddCell().AddParagraph("20")
.AddRow()
.AddCell().AddParagraph("Sandy")
.AddCell().AddParagraph("26")
.AddRow()
.AddCell().AddParagraph("Tom")
.AddCell().AddParagraph("12")
.AddRow()
.AddCell().AddParagraph("Jim")
.AddCell().AddParagraph("27");
// Add input file path
options.AddInput(new FileDataSource("path_to_input.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_output.pdf"));
// Perform the process
PdfManager.AddTable(options);Ejemplo de uso:
El ejemplo muestra cómo añadir una tabla de contenidos a un archivo PDF.
// Create TocOptions object to set instructions
var options = new TocOptions();
// Set the Title
options.Title = "My Table of Contents";
// Design Headings
options.Headings.Add(new TocHeading("Introduction", 2));
options.Headings.Add(new TocHeading("Chapter I", 3));
options.Headings.Add(new TocHeading("Chapter II", 4));
options.Headings.Add(new TocHeading("Chapter III", 5));
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.AddTableOfContents(options);Ejemplo de uso:
El ejemplo muestra cómo añadir una tabla de contenidos a un archivo PDF generando marcadores.
// Create TocOptions object to set instructions
var options = new TocOptions();
// Set the Title
options.Title = "My Table of Contents";
// Generate links in bookmarks
options.GenerateBookmarks = true;
// Design Headings
options.Headings.Add(new TocHeading("Introduction", 2, false, 1));
options.Headings.Add(new TocHeading("Chapter I", 3, true, 1));
options.Headings.Add(new TocHeading("Chapter II", 4, true, 1));
options.Headings.Add(new TocHeading("Example A", 4, true, 2));
options.Headings.Add(new TocHeading("Example B", 4, true, 2));
options.Headings.Add(new TocHeading("Example C", 4, true, 2));
options.Headings.Add(new TocHeading("Example D", 4, true, 2));
options.Headings.Add(new TocHeading("Chapter III", 5, true, 1));
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.AddTableOfContents(options);Ejemplo de uso:
El ejemplo muestra cómo añadir una tabla de contenidos a un archivo PDF y guardarlo como flujo.
// Create TocOptions object to set instructions
var options = new TocOptions();
// Set the Title
options.Title = "My Table of Contents";
// Design Headings
options.Headings.Add(new TocHeading("Introduction", 2, false, 1));
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output stream
var outputStream = new MemoryStream();
options.AddOutput(new StreamDataSource(outputStream));
options.CloseOutputStreams = false;
// Perform the process
PdfManager.AddTableOfContents(options);Mejora de usabilidad de TableGenerator
- Class TableGenerator: es estática y no requiere el uso de un constructor.
- Class TableGenerator: marcada como Obsoleta. Use PdfManager en su lugar.
Mejora de usabilidad de PdfChatGpt
- Class PdfChatGpt: es estática y no requiere el uso de un constructor.
- Class PdfChatGptRequestOptions: se añadió la propiedad CancellationToken (movida desde PdfChatGpt).
Ejemplo de uso:
El ejemplo muestra cómo usar el plugin PdfChatGpt añadiendo mensajes a la solicitud.
var options = new PdfChatGptRequestOptions();
options.AddOutput(new FileDataSource("PdfChatGPT_output.pdf")); // Add the output file path.
options.ApiKey = "Your API key."; // You need to provide the key to access the API.
options.MaxTokens = 1000; // The maximum number of tokens to generate in the chat completion.
// for cancel
// var cancelTokenSource = new CancellationTokenSource();
// var cToken = cancelTokenSource.Token;
// options.CancellationToken = cToken;
// Add the request messages.
options.Messages.Add(new Message
{
Content = "You are a helpful assistant.",
Role = Role.System
});
options.Messages.Add(new Message
{
Content = "What is the biggest pizza diameter ever made?",
Role = Role.User
});
// Process the request.
await PdfChatGpt.ProcessAsync(options);Errores corregidos
- Se corrigió la conversión de HTML a PDF de los metadatos.
- Se corrigió el problema de formato de texto y escalado de imágenes al convertir PDF a PDF/A_3b.
- Se corrigió el error de impresión en los PDFs generados a partir de PDF/A.
- Se solucionó que la imagen resultante de PDF a HTML contenía fondo.
- Se solucionó que algunos caracteres chinos aparecían como cuadros al convertir HTML a PDF.
- Se solucionó que la fuente personalizada en Base64 no se respetaba en la conversión HTML a PDF.
- Se solucionó que el CSS de los campos de formulario no se aplicaba en la conversión HTML a PDF.
- Se solucionó que los gráficos no se renderizaban correctamente al convertir HTML a PDF.
- Se solucionó que los caracteres especiales no se renderizaban en la conversión HTML a PDF.