Class PdfManager
Representa el componente Documentize.PdfManager. Se utiliza para combinar, dividir, optimizar, rotar, cambiar el tamaño, comprimir documentos PDF y agregar tabla, agregar índice a los documentos PDF. Puede combinar varios documentos PDF en un solo PDF. Puede dividir documentos PDF en páginas separadas. Puede optimizar, rotar, cambiar el tamaño y comprimir documentos PDF. Puede rotar y cambiar el tamaño de las páginas de un documento PDF. Puede agregar una tabla a un documento PDF. Puede agregar una tabla de contenidos a un documento PDF.
Representa el componente Documentize.PdfManager. Se utiliza para combinar, dividir, optimizar, rotar, cambiar el tamaño, comprimir documentos PDF y agregar tabla, agregar índice a los documentos PDF.
Puede combinar varios documentos PDF en un solo PDF.
Puede dividir documentos PDF en páginas separadas.
Puede optimizar, rotar, cambiar el tamaño y comprimir documentos PDF.
Puede rotar y cambiar el tamaño de las páginas de un documento PDF.
Puede agregar una tabla a un documento PDF.
Puede agregar una tabla de contenidos a un documento PDF.
public static class PdfManagerHerencia
Miembros heredados
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object?)
- object.Equals(object?, object?)
- object.ReferenceEquals(object?, object?)
- object.GetHashCode()
Métodos
AddTable(TableOptions)
Agregar tabla al documento PDF.
public static ResultContainer AddTable(TableOptions options)Parámetros
optionsTableOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Devuelve
ResultContainer : Un objeto que contiene el resultado de la operación.
Ejemplos
El ejemplo muestra cómo agregar 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 FileData("path_to_input.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_output.pdf"));
// Perform the process
PdfManager.AddTable(options);El ejemplo muestra cómo agregar una tabla a un archivo PDF antes de la página 2.
// Configure table options
var options = new TableOptions();
options.InsertPageBefore(2) // Add table before page 2
.AddTable()
.AddRow()
.AddCell().AddParagraph("Name")
.AddCell().AddParagraph("Age");
// Add input file path
options.AddInput(new FileData("path_to_input.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_output.pdf"));
// Perform the process
PdfManager.AddTable(options);Excepciones
ArgumentException – Si no se establecen las opciones.
AddTableOfContents(TocOptions)
Agregar tabla de contenidos (TOC) al documento PDF.
public static ResultContainer AddTableOfContents(TocOptions options)Parámetros
optionsTocOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Devuelve
ResultContainer : Un objeto que contiene el resultado de la operación.
Ejemplos
El ejemplo muestra cómo agregar 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 FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.AddTableOfContents(options);El ejemplo muestra cómo agregar 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 FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.AddTableOfContents(options);El ejemplo muestra cómo agregar 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 FileData("path_to_your_pdf_file.pdf"));
// Set output stream
var outputStream = new MemoryStream();
options.AddOutput(new StreamData(outputStream));
options.CloseOutputStreams = false;
// Perform the process
PdfManager.AddTableOfContents(options);El ejemplo muestra cómo personalizar el encabezado de la tabla de contenidos.
// Create TocOptions object to set instructions
var heading = new TocHeading();
heading.Text = "Intro";
heading.PageNumber = 5;
heading.GenerateNumbering = true;
heading.Level = 2;
var tocOptions = new TocOptions();
tocOptions.Headings.Add(heading);
// Add input and output files
tocOptions.AddInput(new FileData("path_to_your_pdf_file.pdf"));
tocOptions.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Generate the TOC with customized options
PdfManager.AddTableOfContents(tocOptions);Excepciones
ArgumentException – Si no se establecen las opciones.
Compress(CompressOptions)
Comprimir documento PDF. Intentar reducir el tamaño del documento.
public static ResultContainer Compress(CompressOptions options)Parámetros
optionsCompressOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Devuelve
ResultContainer : Un objeto que contiene el resultado de la operación.
Ejemplos
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 FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Compress(options);Excepciones
ArgumentException – Si no se establecen las opciones.
CreatePdfByChatGptRequestAsync(ChatGptRequestOptions)
Crear documento PDF a partir de la respuesta de ChatGpt.
Se utiliza para enviar solicitudes a ChatGPT directamente o añadiendo fuentes de archivos PDF y guardar la respuesta en la fuente de salida.
public static Task<ResultContainer> CreatePdfByChatGptRequestAsync(ChatGptRequestOptions options)Parámetros
optionsChatGptRequestOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Devuelve
Task<ResultContainer> – Un objeto que contiene el resultado de la operación.
Ejemplos
El ejemplo muestra cómo usar ChatGpt añadiendo mensajes a la solicitud.
var options = new ChatGptRequestOptions();
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
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.
// 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.
var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);
var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion; // The ChatGPT API chat completion object.El ejemplo muestra cómo usar ChatGpt añadiendo un solo mensaje a la solicitud.
var options = new ChatGptRequestOptions();
options.AddOutput(new FileData("path_to_result_pdf_file.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.
// Add the request message.
// In this case, the system message with Content = "You are a helpful assistant." is added by default.
// The role of the query message is "user" by default.
options.Query = "What is the lowest temperature recorded on the Earth?";
// Process the request.
var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);
var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion; // The ChatGPT API chat completion object.El ejemplo muestra cómo usar Chat añadiendo archivo(s) como fuente(s) de mensaje.
var options = new ChatGptRequestOptions();
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Add the PDF text source.
// In case of multiple sources, the text from each document will be added to the request message collection
// as a separate message with the role "user".
options.AddInput(new FileData("TextSource.pdf"));
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.
// Add the request message.
// In this case, the system message with Content = "You are a helpful assistant." is added by default.
// The role of the query message is "user" by default.
options.Query = "How many letters in the provided text?";
// Process the request.
var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);
var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion; // The ChatGPT API chat completion object.Excepciones
ArgumentException – Si no se establecen las opciones.
Merge(MergeOptions)
Combinar documentos PDF.
public static ResultContainer Merge(MergeOptions options)Parámetros
optionsMergeOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Devuelve
ResultContainer : Un objeto que contiene el resultado de la operación.
Ejemplos
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 FileData("path_to_your_pdf_file_1.pdf"));
options.AddInput(new FileData("path_to_your_pdf_file_2.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Merge(options);Excepciones
ArgumentException – Si no se establecen las opciones.
Optimize(OptimizeOptions)
Optimizar documento PDF.
Linealizar el documento para
- abrir la primera página lo antes posible;
- mostrar la siguiente página o seguir un enlace a la siguiente página lo antes posible;
- mostrar la página de forma incremental a medida que llegan los datos (mostrar primero los datos más útiles);
- permitir que la interacción del usuario, como seguir un enlace, se realice incluso antes de que se haya recibido y mostrado toda la página.
public static ResultContainer Optimize(OptimizeOptions options)Parámetros
optionsOptimizeOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Devuelve
ResultContainer : Un objeto que contiene el resultado de la operación.
Ejemplos
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 FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Optimize(options);Excepciones
ArgumentException – Si no se establecen las opciones.
Resize(ResizeOptions)
Cambiar el tamaño de las páginas de un documento PDF.
public static ResultContainer Resize(ResizeOptions options)Parámetros
optionsResizeOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Devuelve
ResultContainer : Un objeto que contiene el resultado de la operación.
Ejemplos
El ejemplo muestra cómo cambiar el tamaño 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 FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Resize(options);Excepciones
ArgumentException – Si no se establecen las opciones.
Rotate(RotateOptions)
Rotar páginas de un documento PDF.
public static ResultContainer Rotate(RotateOptions options)Parámetros
optionsRotateOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Devuelve
ResultContainer : Un objeto que contiene el resultado de la operación.
Ejemplos
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 FileData("path_to_your_pdf_file.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
// Perform the process
PdfManager.Rotate(options);Excepciones
ArgumentException – Si no se establecen las opciones.
Split(SplitOptions)
Dividir documento PDF por páginas.
public static ResultContainer Split(SplitOptions options)Parámetros
optionsSplitOptions: Un objeto de opciones que contiene las instrucciones para la operación.
Devuelve
ResultContainer : Un objeto que contiene el resultado de la operación.
Ejemplos
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 FileData("path_to_your_pdf_file.pdf"));
// Set output file paths
options.AddOutput(new FileData("path_to_result_pdf_file_1.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file_2.pdf"));
// Perform the process
PdfManager.Split(options);Excepciones
ArgumentException – Si no se establecen las opciones.
Namespace: Documentize
Assembly: Documentize.dll