Class PdfManager
Representa el componente Documentize.PdfManager. Se utiliza para combinar, dividir, optimizar, rotar, cambiar el tamaño, comprimir documentos PDF y agregar tablas, agregar índice a 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, comprimir documentos PDF. Puede rotar, cambiar el tamaño de páginas de un documento PDF. Puede agregar una tabla a un PDF. Puede agregar un índice a un PDF.
Representa el componente Documentize.PdfManager. Se utiliza para combinar, dividir, optimizar, rotar, cambiar el tamaño, comprimir documentos PDF y agregar tablas, agregar índice a 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, comprimir documentos PDF.
Puede rotar, cambiar el tamaño de páginas de un documento PDF.
Puede agregar una tabla a un PDF.
Puede agregar un índice a un PDF.
public static class PdfManagerInheritance
Inherited Members
- object.GetType(),
- object.MemberwiseClone(),
- object.ToString(),
- object.Equals(object?),
- object.Equals(object?, object?),
- object.ReferenceEquals(object?, object?),
- object.GetHashCode()
Methods
AddTable(TableOptions)
Agregar una tabla al documento PDF.
public static ResultContainer AddTable(TableOptions options)Parameters
optionsTableOptions: Un objeto de opciones que contiene instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
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);Exceptions
If options not set.
AddTableOfContents(TocOptions)
Agregar un índice (TOC) al documento PDF.
public static ResultContainer AddTableOfContents(TocOptions options)Parameters
optionsTocOptions: Un objeto de opciones que contiene instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
El ejemplo muestra cómo agregar un índice 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 un índice 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 un índice 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 agregar un índice a un archivo PDF personalizando el encabezado del TOC.
// 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);Exceptions
If options not set.
Compress(CompressOptions)
Comprimir documento PDF. Intentar reducir el tamaño del documento.
public static ResultContainer Compress(CompressOptions options)Parameters
optionsCompressOptions: Un objeto de opciones que contiene instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
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);Exceptions
If options not set.
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)Parameters
optionsChatGptRequestOptions: Un objeto de opciones que contiene instrucciones para la operación.
Returns
Un objeto que contiene el resultado de la operación.
Examples
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) del 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.Exceptions
ArgumentException : If options not set.
Merge(MergeOptions)
Combinar documentos PDF.
public static ResultContainer Merge(MergeOptions options)Parameters
optionsMergeOptions: Un objeto de opciones que contiene instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
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);Exceptions
If options not set.
Optimize(OptimizeOptions)
Optimizar documento PDF.
Linealizar el documento para
- abrir la primera página lo más rápido posible;
- mostrar la siguiente página o seguir el enlace a la siguiente página lo más rápido posible;
- mostrar la página de forma incremental a medida que llega, cuando los datos de una página se entregan a través de un canal lento (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 reciba y muestre toda la página.
public static ResultContainer Optimize(OptimizeOptions options)Parameters
optionsOptimizeOptions: Un objeto de opciones que contiene instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
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);Exceptions
If options not set.
Resize(ResizeOptions)
Cambiar el tamaño de páginas de un documento PDF.
public static ResultContainer Resize(ResizeOptions options)Parameters
optionsResizeOptions: Un objeto de opciones que contiene instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
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);Exceptions
If options not set.
Rotate(RotateOptions)
Rotar páginas de un documento PDF.
public static ResultContainer Rotate(RotateOptions options)Parameters
optionsRotateOptions: Un objeto de opciones que contiene instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
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);Exceptions
If options not set.
Split(SplitOptions)
Dividir documento PDF por páginas.
public static ResultContainer Split(SplitOptions options)Parameters
optionsSplitOptions: Un objeto de opciones que contiene instrucciones para la operación.
Returns
ResultContainer : Un objeto que contiene el resultado de la operación.
Examples
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);Exceptions
If options not set.
Namespace: Documentize Assembly: Documentize.dll