v25.11
新插件 PDF Converter
- Class PdfConverter:包含所有插件功能:DocConverter、XlsConverter、HtmlConverter、JpegConverter、PdfAConverter、PngConverter、TiffConverter。
- Class DocConverter:即将删除,请使用 PdfConverter。
- Class XlsConverter:即将删除,请使用 PdfConverter。
- Class HtmlConverter:即将删除,请使用 PdfConverter。
- Class JpegConverter:即将删除,请使用 PdfConverter。
- Class PdfAConverter:即将删除,请使用 PdfConverter。
- Class PngConverter:即将删除,请使用 PdfConverter。
- Class TiffConverter:即将删除,请使用 PdfConverter。
- Class PdfAConvertOptions:已重命名为 Class PdfToPdfAOptions。
- 请参阅 新插件架构。
示例用法:
此示例演示如何将 PDF 文档转换为 Doc 格式。
// Create PdfToDocOptions object to set instructions
var options = new PdfToDocOptions();
// 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_file.doc"));
// Perform the process
PdfConverter.Convert(options);示例用法:
此示例演示如何将 PDF 转换为 XLSX 文档。
// Create PdfToXlsOptions object to set instructions
var options = new PdfToXlsOptions();
// 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_xlsx_file.xlsx"));
// Perform the process
PdfConverter.Convert(options);示例用法:
此示例演示如何将 PDF 转换为 HTML 文档。
// Create PdfToHtmlOptions object to set output data type as file with embedded resources
var options = new PdfToHtmlOptions(PdfToHtmlOptions.SaveDataType.FileWithEmbeddedResources);
// Add input file path
options.AddInput(new FileDataSource("path_to_input.pdf"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_output.html"));
//Perform the process
PdfConverter.Convert(options);示例用法:
此示例演示如何将 HTML 转换为 PDF 文档。
// Create HtmlToPdfOptions
var options = new HtmlToPdfOptions();
// Add input file path
options.AddInput(new FileDataSource("path_to_input.html"));
// Set output file path
options.AddOutput(new FileDataSource("path_to_output.pdf"));
//Perform the process
PdfConverter.Convert(options);示例用法:
此示例演示如何将 PDF 文档转换为 JPEG 格式。
// Create PdfToJpegOptions object to set instructions
var options = new PdfToJpegOptions();
// Add input File path
options.AddInput(new FileDataSource("path_to_input.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryDataSource("path_to_output_directory"));
// Perform the process
PdfConverter.Convert(options);示例用法:
此示例演示如何将 PDF 文档转换为 PNG 格式。
// Create PdfToPngOptions object to set instructions
var options = new PdfToPngOptions();
// Add input File path
options.AddInput(new FileDataSource("path_to_input.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryDataSource("path_to_output_directory"));
// Perform the process
PdfConverter.Convert(options);示例用法:
此示例演示如何将 PDF 文档转换为 TIFF 格式。
// Create PdfToTiffOptions object to set instructions
var options = new PdfToTiffOptions();
// Add input file path
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryDataSource("path_to_output_directory"));
// Perform the process
PdfConverter.Convert(options);示例用法:
此示例演示如何将 PDF 文档转换为 PDF/A 格式(本例为 PDF/A‑3b):
// Create the options class to set up the conversion process
var options = new PdfToPdfAOptions
{
PdfAVersion = PdfAStandardVersion.PDF_A_3B
};
// Add the source file
options.AddInput(new FileDataSource("path_to_your_pdf_file.pdf")); // replace with your actual file path
// Add the path to save the converted file
options.AddOutput(new FileDataSource("path_to_the_converted_file.pdf"));
// Run the conversion
PdfConverter.Convert(options);示例用法:
此示例演示如何验证 PDF 文档是否符合 PDF/A 格式(本例为 PDF/A‑1a):
// Create the options class to set up the validation process
var options = new PdfAValidateOptions
{
PdfAVersion = PdfAStandardVersion.PDF_A_1A
};
// Add one or more files to be validated
options.AddInput(new FileDataSource("path_to_your_first_pdf_file.pdf")); // replace with your actual file path
options.AddInput(new FileDataSource("path_to_your_second_pdf_file.pdf"));
// add more files as needed
// Run the validation and get results
var resultContainer = PdfConverter.Validate(options);
// Check the resultContainer.ResultCollection property for validation results for each file:
for (var i = 0; i < resultContainer.ResultCollection.Count; i++)
{
var result = resultContainer.ResultCollection[i];
var validationResult = (PdfAValidationResult) result.Data;
var isValid = validationResult.IsValid; // Validation result for the i-th document
}新插件 PDF Security
- Class PdfSecurity:包含所有插件功能:Security、Signature、Timestamp。
- Class Security:即将删除,请使用 PdfSecurity。
- Class Signature:即将删除,请使用 PdfSecurity。
- Class Timestamp:即将删除,请使用 PdfSecurity。
- Class DecryptionOptions:已重命名为 Class DecryptOptions。
- Class EncryptionOptions:已重命名为 Class EncryptOptions。
- Class SignOptions:现在包含 Class Timestamp 的属性。
- 请参阅 新插件架构。
示例用法:
此示例演示如何加密 PDF 文档。
// Create EncryptOptions object to set instructions
var options = new EncryptOptions("123456", "qwerty");
// 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
PdfSecurity.Encrypt(options);示例用法:
此示例演示如何解密 PDF 文档。
// Create DecryptOptions object to set instructions
var options = new DecryptOptions("123456");
// 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
PdfSecurity.Decrypt(options);示例用法:
此示例演示如何对 PDF 文档进行签名。
// Create SignOptions object to set instructions
var options = new SignOptions("path_to_your_pfx_file.pfx", "password_of_your_pfx_file");
// 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
PdfSecurity.Sign(options);示例用法:
此示例演示如何在签名时添加时间戳。
// Create SignOptions object to set instructions
var options = new SignOptions("path_to_your_pfx_file.pfx", "password_for_your_pfx_file");
options.TimestampOptions = new TimestampOptions("server_url");
// 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
PdfSecurity.Sign(options);插件 PdfChatGpt 集成到 PdfManager
- Class PdfChatGpt:即将删除,请使用 PdfManager。
- Class PdfChatGptRequestOptions:已重命名为 Class ChatGptRequestOptions。
新增用于 ChatGpt 的选项
- Class ChatCompletion:用于检查请求结果。
- Class Choice:用于检查请求结果。
- Class Usage:用于检查请求结果。
- Class ChatGptConsts:用于使用模型名称、API URL 等额外设置。
示例用法:
此示例演示如何通过向请求添加消息来使用 ChatGpt。
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.增强功能
- PDF 转图片 – 提升转换性能
- PDF 转 TIFF – 提升转换速度
- PDF 转 Doc – 提升性能
已修复的错误
- 修复 HTML 转 PDF 时生成文件的格式问题
- 修复 PDF 转 TIFF 转换中的性能问题
- 修复 HTML 转 PDF 时外部 CSS 资源未正确应用的问题