Extract Images from PDF via C++

Extract images from PDF document. Use Aspose.PDF for C++ to modify PDF files programmatically

Extract Images from PDF Document Using C++ Library

In order to add Image in PDF, we’ll use Aspose.PDF for C++ API which is a feature-rich, powerful and easy to use document manipulation API for cpp platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

Extract Image from PDF via C++


You need Aspose.PDF for C++ to try the code in your environment.

  1. Open PDF document.
  2. Extract a particular image.
  3. Save output image.
  4. Save updated PDF file.

Extract Images from PDF File - C++

This sample code shows how to extract Images from PDF - C++


    // Open document
    auto document = MakeObject<Document>(_dataDir + u"ExtractImages.pdf");

    // Extract a particular image
    auto xImage = document->get_Pages()->idx_get(1)->get_Resources()->get_Images()->idx_get(1);

    auto outputImage = System::IO::File::OpenWrite(_dataDir + u"output.jpg");

    // Save output image
    xImage->Save(outputImage, System::Drawing::Imaging::ImageFormat::get_Jpeg());
    outputImage->Close();

    // Save updated PDF file
    document->Save(_dataDir + u"ExtractImages_out.pdf");