通过 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#

var inputFile = Path.Combine(dataDir, "ExtractImages.pdf");
var outputFile = Path.Combine(dataDir, "ExtractImages_out.pdf");
var imageFile = Path.Combine(dataDir, "aspose-logo.jpg");
var pdfDocument = new Aspose.Pdf.Document(inputFile);

var xImage = pdfDocument.Pages[1].Resources.Images[1];
var outputImage = new FileStream(imageFile, FileMode.Create);
xImage.Save(outputImage, 300);
outputImage.Close();

pdfDocument.Save(outputFile);