Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active July 27, 2021 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/1bca97ec93cc6a52525c2e735da5b3f3 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/1bca97ec93cc6a52525c2e735da5b3f3 to your computer and use it in GitHub Desktop.
Read the complete article about extracting images from PDF files using C++ by visiting the following link.
https://blog.aspose.com/2021/07/12/extract-images-from-pdf-files-using-cpp/
// Load the PDF document
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\PDF\\SampleImages2.pdf");
// Initialize the image counter
int imageCounter = 1;
// Iterate through the pages of the document
for (auto page : pdfDocument->get_Pages())
{
// Iterate through the images of the page
for (auto image : page->get_Resources()->get_Images())
{
// Create an instance of the FileStream
System::SharedPtr<System::IO::FileStream> outputImage = System::IO::File::Create(String::Format(u"OutputDirectory\\Image{0}.jpg", imageCounter));
// Save the image
image->Save(outputImage, System::Drawing::Imaging::ImageFormat::get_Jpeg());
// Close the FileStream
outputImage->Close();
// Increment the image counter
imageCounter++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment