Class PdfConverter

信息

表示 Documentize.PdfConverter 组件。用于将 PDF 文档转换为其他格式,如 DOCX/DOC、XLSX/XLS/CSV/XLSM/ODS、HTML、JPEG、PNG、TIFF、PDF/A。还允许执行 PDF/A 验证并将 HTML 转换为 PDF。

表示 Documentize.PdfConverter 组件。用于将 PDF 文档转换为其他格式,如 DOCX/DOC、XLSX/XLS/CSV/XLSM/ODS、HTML、JPEG、PNG、TIFF、PDF/A。
还允许执行 PDF/A 验证并将 HTML 转换为 PDF。

public static class PdfConverter

Inheritance

objectPdfConverter

Inherited Members

Methods

Convert(PdfToDocOptions)

将 PDF 文档转换为 DOC/DOCX 格式。

public static ResultContainer Convert(PdfToDocOptions options)

Parameters

Returns

ResultContainer : 包含操作结果的对象。

Examples

示例演示如何将 PDF 文档转换为 Doc 格式。

// Create PdfToDocOptions object to set instructions
var options = new PdfToDocOptions();
// 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_file.doc"));
// Perform the process
PdfConverter.Convert(options);

示例演示如何在设置 Mode 的情况下将 PDF 文档转换为 Doc 格式。

// Create PdfToDocOptions object to set instructions
var options = new PdfToDocOptions();
// 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_file.doc"));
// Set Mode
options.Mode = DocConversionMode.Flow;
// Perform the process
PdfConverter.Convert(options);

Exceptions

ArgumentException

如果未设置 options。

Convert(PdfToXlsOptions)

将 PDF 文档转换为 XLSX/XLS/CSV/XLSM/ODS 格式。

public static ResultContainer Convert(PdfToXlsOptions options)

Parameters

Returns

ResultContainer : 包含操作结果的对象。

Examples

示例演示如何将 PDF 转换为 XLSX 文档。

// Create PdfToXlsOptions object to set instructions
var options = new PdfToXlsOptions();
// 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_xlsx_file.xlsx"));
// Perform the process
PdfConverter.Convert(options);

示例演示如何将 PDF 转换为 XLS 文档。

// Create PdfToXlsOptions object to set instructions
var options = new PdfToXlsOptions();
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Specify XLS format
options.Format = PdfToXlsOptions.ExcelFormat.XMLSpreadSheet2003;
options.InsertBlankColumnAtFirst = true;
options.MinimizeTheNumberOfWorksheets = true;
// Set output file path
options.AddOutput(new FileData("path_to_result_xlsx_file.xls"));
// Perform the process
PdfConverter.Convert(options);

Exceptions

ArgumentException

如果未设置 options。

Convert(PdfToHtmlOptions)

将 PDF 文档转换为 HTML 格式。

public static ResultContainer Convert(PdfToHtmlOptions options)

Parameters

Returns

ResultContainer : 包含操作结果的对象。

Examples

示例演示如何将 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 FileData("path_to_input.pdf"));
// Set output file path
options.AddOutput(new FileData("path_to_output.html"));
//Perform the process
PdfConverter.Convert(options);

Exceptions

ArgumentException

如果未设置 options。

Convert(HtmlToPdfOptions)

将 HTML 文档转换为 PDF 格式。

public static ResultContainer Convert(HtmlToPdfOptions options)

Parameters

Returns

ResultContainer : 包含操作结果的对象。

Examples

示例演示如何将 HTML 转换为 PDF 文档。

// Create HtmlToPdfOptions
var options = new HtmlToPdfOptions();
// Add input file path
options.AddInput(new FileData("path_to_input.html"));
// Set output file path
options.AddOutput(new FileData("path_to_output.pdf"));
//Perform the process
PdfConverter.Convert(options);

Exceptions

ArgumentException

如果未设置 options。

Convert(PdfToJpegOptions)

将 PDF 文档转换为 JPEG 格式。

public static ResultContainer Convert(PdfToJpegOptions options)

Parameters

Returns

ResultContainer : 包含操作结果的对象。

Examples

示例演示如何将 PDF 文档转换为 JPEG 格式。

// Create PdfToJpegOptions object to set instructions
var options = new PdfToJpegOptions();
// Add input File path
options.AddInput(new FileData("path_to_input.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryData("path_to_output_directory"));
// Perform the process
PdfConverter.Convert(options);

示例演示如何在设置页面、分辨率、质量的情况下将 PDF 文档转换为 JPEG 格式。

// Create PdfToJpegOptions object to set instructions
var options = new PdfToJpegOptions();
// Process only the first page
options.PageList = [1];
// Set output resolution to 200 DPI
options.OutputResolution = 200;
// Set output quality to 50
options.Quality = 50;
// Add input File path
options.AddInput(new FileData("path_to_input.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryData("path_to_output_directory"));
// 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 FileData("path_to_input.pdf"));
// Perform the process
var results = PdfConverter.Convert(options);
// Get stream results
foreach (var result in results.ResultCollection)
{
    var streamResultPage1 = result.ToStream();
}

Exceptions

ArgumentException

如果未设置 options。

Convert(PdfToPngOptions)

将 PDF 文档转换为 PNG 格式。

public static ResultContainer Convert(PdfToPngOptions options)

Parameters

Returns

ResultContainer : 包含操作结果的对象。

Examples

示例演示如何将 PDF 文档转换为 PNG 格式。

// Create PdfToPngOptions object to set instructions
var options = new PdfToPngOptions();
// Add input File path
options.AddInput(new FileData("path_to_input.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryData("path_to_output_directory"));
// Perform the process
PdfConverter.Convert(options);

示例演示如何将 PDF 文档的单页转换为 PNG 格式。

// Create PdfToPngOptions object to set instructions
var options = new PdfToPngOptions()
// Process only the first page
options.PageList = [1];
// Set output resolution to 200 DPI
options.OutputResolution = 200;
// Add input File path
options.AddInput(new FileData("path_to_input.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryData("path_to_output_directory"));
// Perform the process
PdfConverter.Convert(options);

示例演示如何将 PDF 文档转换为 PNG 流。

// Create PdfToJpegOptions object to set instructions
var options = new PdfToPngOptions();
// Add input File path
options.AddInput(new FileData("path_to_input.pdf"));
// Perform the process
var results = PdfConverter.Convert(options);
// Get stream results
foreach (var result in results.ResultCollection)
{
    var streamResultPage1 = result.ToStream();
}

Exceptions

ArgumentException

如果未设置 options。

Convert(PdfToTiffOptions)

将 PDF 文档转换为 TIFF 格式。

public static ResultContainer Convert(PdfToTiffOptions options)

Parameters

Returns

ResultContainer : 包含操作结果的对象。

Examples

示例演示如何将 PDF 文档转换为 TIFF 格式。

// Create PdfToTiffOptions object to set instructions
var options = new PdfToTiffOptions();
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryData("path_to_output_directory"));
// Perform the process
PdfConverter.Convert(options);

示例演示如何在自定义页面和 DPI 的情况下将 PDF 文档转换为 TIFF 格式。

// Create PdfToTiffOptions object to set instructions
var options = new PdfToTiffOptions();
// Add input file path
options.AddInput(new FileData("path_to_your_pdf_file.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryData("path_to_output_directory"));
// Set Pages
options.PageList = [1, 3];
// Set result image Resolution
options.OutputResolution = 400;
// 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 FileData("path_to_your_pdf_file.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryData("path_to_output_directory"));
// Enable Multi-Page TIFF output
options.MultiPage = true;
// 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 FileData("path_to_your_pdf_file.pdf"));
// Set output Directory path
options.AddOutput(new DirectoryData("path_to_output_directory"));
// Set Compression and ColorDepth
options.Compression = TiffCompression.RLE;
options.ColorDepth = TiffColorDepth.Format24bpp;
// 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 FileData("path_to_input.pdf"));
// Perform the process
var results = PdfConverter.Convert(options);
// Get stream results
foreach (var result in results.ResultCollection)
{
    var streamResultPage1 = result.ToStream();
}

Exceptions

ArgumentException

如果未设置 options。

Convert(PdfToPdfAOptions)

将 PDF 文档转换为 PDF/A 格式。

public static ResultContainer Convert(PdfToPdfAOptions options)

Parameters

Returns

ResultContainer : 包含操作结果的对象。

Examples

示例演示如何将 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 FileData("path_to_your_pdf_file.pdf")); // replace with your actual file path

// Add the path to save the converted file
options.AddOutput(new FileData("path_to_the_converted_file.pdf"));

// Run the conversion
PdfConverter.Convert(options);

Exceptions

ArgumentException

如果未设置 options。

Validate(PdfAValidateOptions)

检查 PDF 文档是否符合指定的 PDF/A 格式。

public static ResultContainer Validate(PdfAValidateOptions options)

Parameters

Returns

ResultContainer : 包含操作结果的对象。

Examples

示例演示如何验证 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 FileData("path_to_your_first_pdf_file.pdf")); // replace with your actual file path
options.AddInput(new FileData("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:
foreach (var result in resultContainer.ResultCollection)
{
    var validationResult = (PdfAValidationResult) result.Data;
    var isValid = validationResult.IsValid; // Validation result for document
}

Exceptions

ArgumentException

如果未设置 options。

Namespace: Documentize Assembly: Documentize.dll

 中文