Last active
July 27, 2021 16:11
Extract Images from PDF using C++ | https://blog.aspose.com/2021/07/12/extract-images-from-pdf-files-using-cpp/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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