v25.10
新插件 PDF Extractor
- Class PdfExtractor:包含插件的所有功能:TextExtractor、ImageExtractor、FormExporter。
- Class TextExtractor:即将删除,请使用 PdfExtractor。
- Class ImageExtractor:即将删除,请使用 PdfExtractor。
- Class FormExporter:即将删除,请使用 PdfExtractor。
- Class TextExtractorOptions:已重命名为 Class ExtractTextOptions。
- Class ImageExtractorOptions:已重命名为 Class ExtractImagesOptions。
- Class FormExportToDsvOptions:已重命名为 Class ExtractFormDataToDsvOptions。
- 参见 The New Plugin Architecture。
示例用法:
演示如何提取 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();示例用法:
演示如何在 TextFormattingMode 下提取 PDF 文档的文本内容。
// 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();示例用法:
演示如何从 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();示例用法:
演示如何将表单值导出为 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);新插件 PDF Manager
- Class PdfManager:包含插件的所有功能:Merger、Optimizer、Splitter、TableGenerator、TocGenerator。
- Class Merger:即将删除。
- Class Optimizer:即将删除,请使用 PdfManager。
- Class Splitter:即将删除,请使用 PdfManager。
- Class TableGenerator:即将删除,请使用 PdfManager。
- Class TocGenerator:即将删除,请使用 PdfManager。
- 参见 The New Plugin Architecture。
示例用法:
演示如何合并两个 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);示例用法:
演示如何拆分 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);示例用法:
演示如何优化 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);示例用法:
演示如何旋转 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);示例用法:
演示如何重新设置 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);示例用法:
演示如何压缩 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);示例用法:
演示如何向 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);示例用法:
演示如何向 PDF 文件添加目录(Table of Contents)。
// 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);示例用法:
演示如何在生成目录时创建书签。
// 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);示例用法:
演示如何将目录保存为流。
// 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);TableGenerator 可用性改进
- Class TableGenerator:已设为静态,无需使用构造函数。
- Class TableGenerator:已标记为过时,请改用 PdfManager。
PdfChatGpt 可用性改进
- Class PdfChatGpt:已设为静态,无需使用构造函数。
- Class PdfChatGptRequestOptions:新增属性
CancellationToken(从 PdfChatGpt 移动而来)。
示例用法:
演示如何通过向请求添加消息来使用 PdfChatGpt 插件。
var options = new PdfChatGptRequestOptions();
options.AddOutput(new FileDataSource("PdfChatGPT_output.pdf")); // 添加输出文件路径。
options.ApiKey = "Your API key."; // 需要提供用于访问 API 的密钥。
options.MaxTokens = 1000; // Chat 完成时生成的最大 token 数量。
// 取消示例
// var cancelTokenSource = new CancellationTokenSource();
// var cToken = cancelTokenSource.Token;
// options.CancellationToken = cToken;
// 添加请求消息。
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
});
// 处理请求。
await PdfChatGpt.ProcessAsync(options);已修复的错误
- 修复了 HTML 转 PDF 时的元数据问题
- 修复了 PDF 转
PDF/A_3b时的文本格式和图片缩放问题 - 修复了 PDF 转 PDFA 时生成的文件在打印时出现错误
- 修复了 PDF 转 HTML 时生成的图像包含背景
- 修复了 HTML 转 PDF 时部分中文字符显示为方框
- 修复了 HTML 转 PDF 时 Base64 自定义字体未生效
- 修复了 HTML 转 PDF 时表单字段 CSS 未被应用
- 修复了 HTML 转 PDF 时图表未正确渲染
- 修复了 HTML 转 PDF 时特殊字符未渲染