PDF Image Extractor

Documentize PDF Image Extractor for .NET 插件使您能够轻松从 PDF 文档中提取图像。它扫描您的 PDF 文件,识别嵌入的图像,并提取它们,同时保持原始质量和格式。此工具增强了视觉内容的可访问性,并简化了从 PDF 中检索图像的过程。

如何从 PDF 中提取图像

要从 PDF 文件中提取图像,请按照以下步骤操作:

  1. 创建 ImageExtractor 类的实例。
  2. 创建 ImageExtractorOptions 类的实例。
  3. 将输入文件路径添加到选项中。
  4. 使用插件处理图像提取。
  5. 从结果容器中检索提取的图像。
 1using var plugin = new ImageExtractor();
 2
 3// Create an instance of the ImageExtractorOptions class
 4var imageExtractorOptions = new ImageExtractorOptions();
 5
 6// Add the input file path
 7imageExtractorOptions.AddInput(new FileDataSource(Path.Combine(@"C:\Samples\", "sample.pdf")));
 8
 9// Process the image extraction
10var resultContainer = plugin.Process(imageExtractorOptions);
11
12// Get the extracted image and save it to a file
13var extractedImage = resultContainer.ResultCollection[0].ToStream();
14var outputStream = File.OpenWrite(@"C:\Samples\tmp.jpg");
15extractedImage.CopyTo(outputStream);

从多个 PDF 文件中提取图像

ImageExtractor 插件支持批处理,使您能够同时从多个 PDF 中提取图像。此功能在您有一系列 PDF 文件并需要一次性检索所有图像时特别有用。

 1using var plugin = new ImageExtractor();
 2var options = new ImageExtractorOptions();
 3
 4// Add multiple input PDF files
 5options.AddInput(new FileDataSource(@"C:\Samples\file1.pdf"));
 6options.AddInput(new FileDataSource(@"C:\Samples\file2.pdf"));
 7options.AddInput(new FileDataSource(@"C:\Samples\file3.pdf"));
 8
 9// Process the image extraction
10var resultContainer = plugin.Process(options);
11
12// Save the extracted images from all files
13for (int i = 0; i < resultContainer.ResultCollection.Count; i++)
14{
15    var extractedImage = resultContainer.ResultCollection[i].ToStream();
16    using var outputStream = File.OpenWrite($@"C:\Samples\image_{i + 1}.jpg");
17    extractedImage.CopyTo(outputStream);
18}

主要特性:

  • 提取嵌入图像:识别并提取 PDF 文档中的图像。
  • 保持图像质量:确保提取的图像保留其原始质量。
  • 批处理:在一次操作中从多个 PDF 文档中提取图像。
  • 灵活输出:以您喜欢的格式或位置保存提取的图像。
 中文