Extract Images from PDF File

Contents
[ ]

The following code snippet also work with Aspose.PDF.Drawing library.

Images are held in each page’s Resources collection’s Images collection. To extract a particular page, then get the image from the Images collection using the particular index of the image.

The image’s index returns an XImage object. This object provides a Save method which can be used to save the extracted image. The following code snippet shows how to extract images from a PDF file.

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();

// Open document
using (Document document = new Document(dataDir +  "ExtractImages.pdf"))
{
    // Extract a particular image
    XImage xImage = document.Pages[1].Resources.Images[1];

    using (FileStream outputImage = new FileStream(dataDir + "output.jpg", FileMode.Create))
    {
        // Save output image
        xImage.Save(outputImage, ImageFormat.Jpeg);
    }

    // Save updated PDF file
    document.Save(dataDir + "ExtractImages_out.pdf");
}