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, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExtractImageFromPDF()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "ExtractImages.pdf"))
    {
        // Extract a particular image
        var xImage = document.Pages[1].Resources.Images[1];
        using (var outputImage = new FileStream(dataDir + "ExtractedImage.jpg", FileMode.Create))
        {
            // Save PDF document image
            xImage.Save(outputImage, System.Drawing.Imaging.ImageFormat.Jpeg);
        }

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