
PDF is a popular format for sharing and printing documents due to its consistent layout. However, you might find yourself in situations where you want to generate a cover image of the PDF file or embed its pages on a web page. In such cases, converting the PDF file to image format will prove to be helpful. To that end, this article will teach you how to convert PDF pages to PNG images using C++.
- C++ API for Converting PDF Pages to PNG Images
- Convert PDF Pages to PNG Images using C++
- Convert a Single PDF Page to a PNG Image using C++
C++ API for Converting PDF to PNG Images
Aspose.PDF for C++ is a C++ library that allows you to create, read and update PDF documents. Furthermore, the API supports converting PDF pages to PNG images. You can either install the API through NuGet or download it directly from the downloads section.
PM> Install-Package Aspose.PDF.Cpp
Convert PDF Pages to PNG Images in C++
The following are the steps to convert PDF pages to PNG images.
- Load the PDF file using the Document class.
- Iterate through the pages of the PDF file.
- Within the loop, create an instance of the FileStream class for the output image.
- Create an instance of the Resolution class.
- Create an instance of the PngDevice class.
- Using the Process (System::SharedPtr page, System::SharedPtrSystem::IO::Stream output) method of the PngDevice class, save the image of the PDF page.
The following sample code demonstrates how to save the pages of a PDF file as PNG images using C++.
Convert a Page in PDF to a PNG in C++
The following are the steps to convert a single page of a PDF file to a PNG image.
- Load the PDF file using the Document class.
- Retrieve the page that you want to convert using the Document->get_Pages()->idx_get(int32_t index) method.
- Create an instance of the FileStream class for the output image.
- Instantiate an object of the Resolution class.
- Create an instance of the PngDevice class.
- Using the Process (System::SharedPtr page, System::SharedPtrSystem::IO::Stream output) method of the PngDevice class, save the image of the PDF page.
The following sample code shows how to convert a single PDF page to a PNG image using C++.
Free C++ PDF to PNG Conversion
You can get a free temporary license and convert PDF files to PNG images in C++ without any limitations.
Explore PDF to PNG Converter
You can explore the C++ PDF to PNG converter in detail by visiting the official documentation. In case of any questions, please feel free to reach us at our free support forum.
Conclusion
In this article, you have learned how to convert the pages of a PDF file to PNG images using C++. You can convert all the pages or selected pages of PDF files to PNG images. Aspose.PDF for C++ is a robust API with many additional features for automating your PDF-related workflows.