通过 C# 从 PDF 中提取图像

C# 使用自己的 API 从 PDF 中提取图像的库。

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

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

Package Manager Console

PM > Install-Package Aspose.PDF

通过 C# 从 PDF 中提取图像


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

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

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

<% images-extract.code-block.subtitle %>


// 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);