Extract images from PDF in C++

How to Extract images from PDF using C++

How to extract images from PDF using Aspose.PDF for C++ Tool

Do you need to extract images from PDF? Programmatic modification of PDF documents is an essential part of modern digital workflows. With C++ libraries like Aspose.PDF, developers can extract images from PDF. These libraries are stand-alone solutions that don’t rely on other software and are ready for commercial use. They cover all possible needs of professional C++ developers.

  • Extract text from PDF
  • Extract Images from PDF
  • Extract Fonts from PDF
  • Extract Data from the Form
  • Extract Text From Stamps
  • Extract Data from Table

In order to extract images from PDF file, 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 images from PDF in C++


You need Aspose.PDF for C++ 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 - C++

This sample code shows how to extract images from PDF documents

Input file:

File not added

Output format:

PDF

Output file:

    void ExtractImage()
{
    std::clog << __func__ << ": Start" << std::endl;
    // String for path name
    String _dataDir("C:\\Samples\\Parsing\\");

    // String for file name
    String infilename("sample-image.pdf");
    String outfilename("extracted_image.jpeg");

    // Open document
    auto document = MakeObject<Document>(_dataDir + infilename);

    // 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 + outfilename);

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

    std::clog << __func__ << ": Finish" << std::endl;
}

About Aspose.PDF for C++ API

Aspose.PDF for C++ is a powerful processing library that enables developers to create, read and manipulate PDF documents without using Adobe Acrobat. It provides a wide range of features, such as creating forms, adding/editing text, manipulating PDF pages, adding annotations, handling custom fonts and much more.

Aspose.PDF for C++ is a library that enables developers to add PDF processing capabilities to their applications. API can be used to build 32-bit and 64-bit applications to generate, read, convert, and manipulate PDF files without using Adobe Acrobat.

In the API reference, you can find detailed explanations & examples for every class & method in Aspose.PDF for C++ library. It also recommends viewing a Documentation.