Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save aspose-com-gists/27a116c958c8271756c87ef3df9c0705 to your computer and use it in GitHub Desktop.
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/
// 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();
}
// 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