Extract images from PDF in PHP

How to Extract images from PDF using PHP via Java

How to extract images from PDF using Aspose.PDF for PHP via Java Tool

In order to extract images PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful, and easy-to-use document manipulation API for php-java platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Extract images from PDF in PHP


You need Aspose.PDF library to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Create an XImage object to extract images.
  3. Save output image to jpeg file.
  4. Save updated PDF file.

Extract images from PDF - PHP

This sample code shows how to extract images from PDF documents

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

About Aspose.PDF for PHP via Java API

Our .NET Library can combine a document from any supported download format to any supported save format. Aspose.PDF for .NET library provides fairly universal solutions that will help you solve the tasks of merging documents. Aspose.PDF supports the most significant number of popular document formats, both for loading and saving. Draw your attention to the fact that the current section describes only popular merges. The current page provides information about merging IMAGES to {{FILERESULT}}. However, there are many combinations for merging your files. For a complete list of supported formats, see the section Supported File Formats.