Class PdfManager

Thông tin

Đại diện cho plugin Documentize.PdfManager. Được sử dụng để Gộp, Tách, Tối ưu, Xoay, Thay đổi kích thước, Nén các tài liệu PDF và Thêm Bảng, Thêm Mục lục (TOC) vào tài liệu PDF. Có thể Gộp nhiều tài liệu PDF thành một PDF duy nhất. Có thể Tách tài liệu PDF thành các trang riêng biệt. Có thể Tối ưu, Xoay, Thay đổi kích thước, Nén tài liệu PDF. Có thể Xoay, Thay đổi kích thước các Trang của tài liệu PDF. Có thể Thêm Bảng vào tài liệu PDF. Có thể Thêm Mục lục vào tài liệu PDF.

Represents Documentize.PdfManager plugin. Used to Merge, Split, Optimize, Rotate, Resize, Compress PDF documents and Add Table, Add TOC to PDF documents. Can Merge multiple PDF documents into a single PDF. Can Split PDF documents into separate pages. Can Optimize, Rotate, Resize, Compress PDF documents. Can Rotate, Resize Pages of PDF document. Can Add a Table to a PDF document. Can Add a Table of Contents to PDF document.

public static class PdfManager

Inheritance

objectPdfManager

Inherited Members

Examples

The example demonstrates how to Merge two PDF documents.

// 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);

The example demonstrates how to Split PDF document.

// 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);

The example demonstrates how to Optimize PDF document.

// 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);

The example demonstrates how to Rotate PDF document.

// 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);

The example demonstrates how to Resize PDF document.

// 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);

The example demonstrates how to Compress PDF document.

// 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);

The example demonstrates how to Add Table to PDF file.

// 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);

The example demonstrates how to add Table of Contents to PDF file.

// 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);

The example demonstrates how to add Table of Contents to PDF file with generating bookmarks.

// 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);

The example demonstrates how to add Table of Contents to PDF file and save as stream.

// 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);

The example demonstrates how to use ChatGpt by adding messages to the request.

var options = new ChatGptRequestOptions();
// Set output file path
options.AddOutput(new FileDataSource("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.

The example demonstrates how to use ChatGpt by adding one message to the request.

var options = new ChatGptRequestOptions();
options.AddOutput(new FileDataSource("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.

The example demonstrates how to use Chat by adding file(s) as the message source(s).

var options = new ChatGptRequestOptions();
// Set output file path
options.AddOutput(new FileDataSource("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 FileDataSource("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.

Methods

AddTable(TableOptions)

Add Table to PDF document.

public static ResultContainer AddTable(TableOptions options)

Parameters

  • options TableOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Exceptions

ArgumentException

If options not set.

AddTableOfContents(TocOptions)

Add Table of Contents (TOC) to PDF document.

public static ResultContainer AddTableOfContents(TocOptions options)

Parameters

  • options TocOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Exceptions

ArgumentException

If options not set.

Compress(CompressOptions)

Compress PDF document. Try to reduce size of the document.

public static ResultContainer Compress(CompressOptions options)

Parameters

  • options CompressOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Exceptions

ArgumentException

If options not set.

CreatePdfByChatGptRequestAsync(ChatGptRequestOptions)

Create PDF document by Reply of ChatGpt. Used to send requests to ChatGPT directly or by adding PDF file sources and save the reply to the output source.

public static Task<resultcontainer> CreatePdfByChatGptRequestAsync(ChatGptRequestOptions options)

Parameters

Returns

Task<ResultContainer>

An object containing the result of the operation.

Exceptions

ArgumentException : If options not set.

Merge(MergeOptions)

Merge PDF documents.

public static ResultContainer Merge(MergeOptions options)

Parameters

  • options MergeOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Exceptions

ArgumentException

If options not set.

Optimize(OptimizeOptions)

Optimize PDF document. Linearize the document in order to

  • open the first page as quickly as possible;
  • display next page or follow by link to the next page as quickly as possible;
  • display the page incrementally as it arrives when data for a page is delivered over a slow channel (display the most useful data first);
  • permit user interaction, such as following a link, to be performed even before the entire page has been received and displayed.
public static ResultContainer Optimize(OptimizeOptions options)

Parameters

  • options OptimizeOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Exceptions

ArgumentException

If options not set.

Resize(ResizeOptions)

Resize Pages of PDF document.

public static ResultContainer Resize(ResizeOptions options)

Parameters

  • options ResizeOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Exceptions

ArgumentException

If options not set.

Rotate(RotateOptions)

Rotate Pages of PDF document.

public static ResultContainer Rotate(RotateOptions options)

Parameters

  • options RotateOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Exceptions

ArgumentException

If options not set.

Split(SplitOptions)

Split PDF document by pages.

public static ResultContainer Split(SplitOptions options)

Parameters

  • options SplitOptions: An options object containing instructions for the operation.

Returns

ResultContainer : An object containing the result of the operation.

Exceptions

ArgumentException

If options not set.

Namespace: Documentize Assembly: Documentize.dll

 Tiếng Việt