通過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中提取圖像


您需要用於 .NET 庫的 [Aspose.PDF](https://releases.aspose.com/pdf/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);