Class PdfManager

Thông tin

Đại diện cho thành phần Documentize.PdfManager. Được sử dụng để Gộp, Tách, Tối ưu, Xoay, Thay đổi kích thước, Nén tài liệu PDF và Thêm Bảng, Thêm mục lục 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.

Đại diện cho thành phần Documentize.PdfManager. Được sử dụng để Gộp, Tách, Tối ưu, Xoay, Thay đổi kích thước, Nén tài liệu PDF và Thêm Bảng, Thêm mục lục 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.

public static class PdfManager

Inheritance

objectPdfManager

Inherited Members

Methods

AddTable(TableOptions)

Thêm Bảng vào tài liệu PDF.

public static ResultContainer AddTable(TableOptions options)

Tham số

  • options TableOptions: Đối tượng tùy chọn chứa các hướng dẫn cho thao tác.

Trả về

ResultContainer : Đối tượng chứa kết quả của thao tác.

Ví dụ

Ví dụ dưới đây minh họa cách Thêm Bảng vào tập tin PDF.

// Cấu hình tùy chọn bảng
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");
// Thêm đường dẫn tệp đầu vào
options.AddInput(new FileData("path_to_input.pdf"));
// Đặt đường dẫn tệp đầu ra
options.AddOutput(new FileData("path_to_output.pdf"));
// Thực hiện quá trình
PdfManager.AddTable(options);

Ví dụ dưới đây minh họa cách Thêm Bảng vào tập tin PDF trước trang 2.

// Cấu hình tùy chọn bảng
var options = new TableOptions();
options.InsertPageBefore(2) // Thêm bảng trước trang 2
   .AddTable()
        .AddRow()
            .AddCell().AddParagraph("Name")
            .AddCell().AddParagraph("Age");
// Thêm đường dẫn tệp đầu vào
options.AddInput(new FileData("path_to_input.pdf"));
// Đặt đường dẫn tệp đầu ra
options.AddOutput(new FileData("path_to_output.pdf"));
// Thực hiện quá trình
PdfManager.AddTable(options);

Ngoại lệ

ArgumentException

Nếu options không được thiết lập.

AddTableOfContents(TocOptions)

Thêm Mục lục (TOC) vào tài liệu PDF.

public static ResultContainer AddTableOfContents(TocOptions options)

Tham số

  • options TocOptions: Đối tượng tùy chọn chứa các hướng dẫn cho thao tác.

Trả về

ResultContainer : Đối tượng chứa kết quả của thao tác.

Ví dụ

Ví dụ dưới đây minh họa cách thêm Mục lục vào tập tin PDF.

// Tạo đối tượng TocOptions để đặt các chỉ dẫn
var options = new TocOptions();
// Đặt tiêu đề
options.Title = "My Table of Contents";
// Thiết kế các tiêu đề
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));
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.AddTableOfContents(options);

Ví dụ dưới đây minh họa cách thêm Mục lục vào tập tin PDF và tạo các dấu trang.

var options = new TocOptions();
options.Title = "My Table of Contents";
options.GenerateBookmarks = true;
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));
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.AddTableOfContents(options);

Ví dụ dưới đây minh họa cách thêm Mục lục vào tập tin PDF và lưu dưới dạng luồng.

var options = new TocOptions();
options.Title = "My Table of Contents";
options.Headings.Add(new TocHeading("Introduction", 2, false, 1));
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
var outputStream = new MemoryStream();
options.AddOutput(new StreamData(outputStream));
options.CloseOutputStreams = false;
PdfManager.AddTableOfContents(options);

Ví dụ dưới đây minh họa cách thêm Mục lục vào tập tin PDF với việc tùy chỉnh tiêu đề TOC.

var heading = new TocHeading();
heading.Text = "Intro";
heading.PageNumber = 5;
heading.GenerateNumbering = true;
heading.Level = 2;
var tocOptions = new TocOptions();
tocOptions.Headings.Add(heading);
tocOptions.AddInput(new FileData("path_to_your_pdf_file.pdf"));
tocOptions.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.AddTableOfContents(tocOptions);

Ngoại lệ

ArgumentException

Nếu options không được thiết lập.

Compress(CompressOptions)

Nén tài liệu PDF. Cố gắng giảm kích thước tài liệu.

public static ResultContainer Compress(CompressOptions options)

Tham số

  • options CompressOptions: Đối tượng tùy chọn chứa các hướng dẫn cho thao tác.

Trả về

ResultContainer : Đối tượng chứa kết quả của thao tác.

Ví dụ

var options = new CompressOptions();
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.Compress(options);

Ngoại lệ

ArgumentException

Nếu options không được thiết lập.

CreatePdfByChatGptRequestAsync(ChatGptRequestOptions)

Tạo tài liệu PDF từ phản hồi của ChatGpt.
Được sử dụng để gửi yêu cầu tới ChatGPT trực tiếp hoặc bằng cách thêm các nguồn tệp PDF và lưu phản hồi vào nguồn đầu ra.

public static Task<resultcontainer> CreatePdfByChatGptRequestAsync(ChatGptRequestOptions options)

Tham số

Trả về

Task<ResultContainer>

Một đối tượng chứa kết quả của thao tác.

Ví dụ

var options = new ChatGptRequestOptions();
options.AddOutput(new FileData("path_to_result_pdf_file.pdf")); 
options.ApiKey = "Your API key.";
options.MaxTokens = 1000;
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 });
var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);
var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion;
var options = new ChatGptRequestOptions();
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
options.ApiKey = "Your API key.";
options.MaxTokens = 1000;
options.Query = "What is the lowest temperature recorded on the Earth?";
var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);
var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion;
var options = new ChatGptRequestOptions();
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
options.AddInput(new FileData("TextSource.pdf"));
options.ApiKey = "Your API key.";
options.MaxTokens = 1000;
options.Query = "How many letters in the provided text?";
var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);
var fileResultPath = result.ResultCollection[0].Data;
var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion;

Ngoại lệ

ArgumentException : Nếu options không được thiết lập.

Merge(MergeOptions)

Gộp tài liệu PDF.

public static ResultContainer Merge(MergeOptions options)

Tham số

  • options MergeOptions: Đối tượng tùy chọn chứa các hướng dẫn cho thao tác.

Trả về

ResultContainer : Đối tượng chứa kết quả của thao tác.

Ví dụ

var options = new MergeOptions();
options.AddInput(new FileData("path_to_your_pdf_file_1.pdf"));
options.AddInput(new FileData("path_to_your_pdf_file_2.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.Merge(options);

Ngoại lệ

ArgumentException

Nếu options không được thiết lập.

Optimize(OptimizeOptions)

Tối ưu tài liệu PDF.
Linearize tài liệu để

  • mở trang đầu tiên càng nhanh càng tốt;
  • hiển thị trang tiếp theo hoặc theo liên kết tới trang tiếp theo càng nhanh càng tốt;
  • hiển thị trang một cách dần dần khi dữ liệu của một trang được truyền qua kênh chậm (hiển thị dữ liệu hữu ích nhất trước);
  • cho phép tương tác người dùng, chẳng hạn theo liên kết, được thực hiện ngay cả khi chưa nhận và hiển thị toàn bộ trang.
public static ResultContainer Optimize(OptimizeOptions options)

Tham số

  • options OptimizeOptions: Đối tượng tùy chọn chứa các hướng dẫn cho thao tác.

Trả về

ResultContainer : Đối tượng chứa kết quả của thao tác.

Ví dụ

var options = new OptimizeOptions();
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.Optimize(options);

Ngoại lệ

ArgumentException

Nếu options không được thiết lập.

Resize(ResizeOptions)

Thay đổi kích thước các trang của tài liệu PDF.

public static ResultContainer Resize(ResizeOptions options)

Tham số

  • options ResizeOptions: Đối tượng tùy chọn chứa các hướng dẫn cho thao tác.

Trả về

ResultContainer : Đối tượng chứa kết quả của thao tác.

Ví dụ

var options = new ResizeOptions();
options.PageSize = PageSize.A3;
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.Resize(options);

Ngoại lệ

ArgumentException

Nếu options không được thiết lập.

Rotate(RotateOptions)

Xoay các trang của tài liệu PDF.

public static ResultContainer Rotate(RotateOptions options)

Tham số

  • options RotateOptions: Đối tượng tùy chọn chứa các hướng dẫn cho thao tác.

Trả về

ResultContainer : Đối tượng chứa kết quả của thao tác.

Ví dụ

var options = new RotateOptions();
options.Rotation = Rotation.On90;
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
PdfManager.Rotate(options);

Ngoại lệ

ArgumentException

Nếu options không được thiết lập.

Split(SplitOptions)

Tách tài liệu PDF theo trang.

public static ResultContainer Split(SplitOptions options)

Tham số

  • options SplitOptions: Đối tượng tùy chọn chứa các hướng dẫn cho thao tác.

Trả về

ResultContainer : Đối tượng chứa kết quả của thao tác.

Ví dụ

var options = new SplitOptions();
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file_1.pdf"));
options.AddOutput(new FileData("path_to_result_pdf_file_2.pdf"));
PdfManager.Split(options);

Ngoại lệ

ArgumentException

Nếu options không được thiết lập.

Namespace: Documentize Assembly: Documentize.dll

 Tiếng Việt