通过 C# 从 PDF 中提取图像

从 PDF 文档中提取图像。使用 Aspose.PDF for .NET 以编程方式修改 PDF 文件

使用 C# 工具从 PDF 文档中提取图像

为了从 PDF 中提取图像,我们将使用 Aspose.PDF for .NET API,这是一款功能丰富、强大且易于使用的文档操作 API,适用于 net 平台。打开 NuGet 软件包管理器,搜索 Aspose.pdf 并安装。您也可以使用包管理器控制台中的以下命令。

Package Manager Console

PM > Install-Package Aspose.PDF

通过 C# 从 PDF 中提取图像


你需要 Aspose.PDF for .NET 库 才能在你的环境中试用代码。

  1. 打开 PDF 文档。
  2. 提取特定的图像。
  3. 保存输出图像。
  4. 保存更新后的 PDF 文件。

从 PDF 文件中提取图像-C#

此示例代码说明如何从 PDF 中提取图像-C#


// Open document
Document pdfDocument = new Document(dataDir+ "ExtractImages.pdf");

// Extract a particular image
XImage xImage = pdfDocument.Pages[1].Resources.Images[1];

FileStream outputImage = new FileStream(dataDir + "output.jpg", FileMode.Create);

// Save output image
xImage.Save(outputImage, ImageFormat.Jpeg);
outputImage.Close();

dataDir = dataDir + "ExtractImages_out.pdf";

// Save updated PDF file
pdfDocument.Save(dataDir);