以 PHP 从 PDF 中提取图像

如何使用 PHP via Java 从 PDF 中提取图像

如何使用适用于 PHP via Java 工具的 Aspose.PDF 从 PDF 中提取图像

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

以 PHP 从 PDF 中提取图像


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

  1. 在 PDF 中加载 “文档” 实例。
  2. 创建 XImage 对象来提取图像。
  3. 将输出图像保存到 jpeg 文件中。
  4. 保存更新后的 PDF 文件。

从 PDF 中提取图像-PHP

此示例代码显示如何从 PDF 文档中提取图像

Input file:

File not added

Output format:

PDF

Output file:

// Load the PDF document
$document = new Document($inputFile);
// Get the first image from the collection
$xImage = $document->getPages()->get_Item(1)->getResources()->getImages()->get_Item(1);
// Create a new FileOutputStream object to save the image
$outputImage = new java("java.io.FileOutputStream", $outputFile);
// Save the image to the output file
$xImage->save($outputImage);
// Close the output image file
$outputImage->close();

关于 Aspose.PDF for PHP via Java API

我们的.NET 库可以将任何支持的下载格式的文档合并为任何支持的保存格式。.NET 的 Aspose.PDF 库提供了相当通用的解决方案,可以帮助你解决合并文档的任务。Aspose.PDF 支持最多的流行文档格式,用于加载和保存。请注意以下事实:当前部分仅描述流行的合并。当前页面提供有关将 IMAGES 合并到 {{FILERESULT}} 的信息。但是,合并文件有多种组合。有关支持格式的完整列表,请参阅 支持的文件格式 部分。