Last active
July 27, 2021 15:44
Star
You must be signed in to star a gist
Convert PDF Pages to PNG Images using C++ | https://blog.aspose.com/2021/07/16/convert-pdf-pages-to-png-images-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 converting PDF pages to PNG images using C++ by visiting the following link. | |
https://blog.aspose.com/2021/07/16/convert-pdf-pages-to-png-images-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 file | |
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\PDF\\Sample 1.pdf"); | |
// Iterate throught the PDF pages | |
for (auto page : pdfDocument->get_Pages()) | |
{ | |
// Create an instance of the FileStream class | |
System::SharedPtr<System::IO::FileStream> imageStream = System::IO::File::Create(String::Format(u"OutputDirectory\\page_{0}.png", page->get_Number())); | |
// Create an instance of the Resolution class | |
auto resolution = MakeObject<Aspose::Pdf::Devices::Resolution>(300); | |
// Create an instance of the PngDevice class | |
auto pngDevice = MakeObject<Aspose::Pdf::Devices::PngDevice>(500, 700, resolution); | |
// Save the page as image | |
pngDevice->Process(page, imageStream); | |
// Close the stream | |
imageStream->Close(); | |
} |
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 file | |
auto pdfDocument = MakeObject<Document>(u"SourceDirectory\\PDF\\Sample 1.pdf"); | |
// Retrieve the first page | |
auto page = pdfDocument->get_Pages()->idx_get(1); | |
// Create an instance of the FileStream class | |
System::SharedPtr<System::IO::FileStream> imageStream = System::IO::File::Create(String::Format(u"OutputDirectory\\page_{0}.png", page->get_Number())); | |
// Create an instance of the Resolution class | |
auto resolution = MakeObject<Aspose::Pdf::Devices::Resolution>(300); | |
// Create an instance of the PngDevice class | |
auto pngDevice = MakeObject<Aspose::Pdf::Devices::PngDevice>(500, 700, resolution); | |
// Save the page as image | |
pngDevice->Process(page, imageStream); | |
// Close the stream | |
imageStream->Close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment