Free Support Forum - aspose.com

Convert PDF to Image (BMP, JPG, PNG, TIF) in C++ | Aspose.PDF for C++

Hello,

I would like to evaluate Aspose.PDF for C++ in order to integrate it into our commercial software currently under development.

In particular, we are interested in the conversion from PDF to Images (BMP, JPG, PNG, TIF) with layers extraction and original document resolution specification (DPI).

I’ve downloaded the free trial version and tried both the examples shipped with the package and the ones in the git repository at https://github.com/aspose-pdf/Aspose.PDF-for-C with no success.

I wish to know if you could provide some additional resources or a step-by-step guide that illustrates the PDF to Image conversion process.

My development environment is C++ with VS 2017.

Best regards

@vsanelli

Thank you for contacting support.

We would like to request you to use below code snippets in your environment to render a PDF document to images, and then share your kind feedback with us.

PDF to JPG:

// instantiate PdfConverter 
SharedPtr converter = MakeObject(); 
// load an existing PDF document 
converter->BindPdf(dir + L"template.pdf"); 
// convert PDF pages to images 
converter->DoConvert(); int32_t imageCount = 1; 
while (converter->HasNextImage()) { 
// save each page in JPG format 
converter->GetNextImage(dir + imageCount + L".jpg", System::Drawing::Imaging::ImageFormat::get_Jpeg(), 800, 1000); imageCount++; 
} 

PDF to TIFF:

/// <summary>
/// Converts each pages of a pdf document to images and save images to a single TIFF ClassF file.
/// </summary>
/// <param name="outputFile">The stream to save the TIFF image.</param>
/// <example>
/// 
/// <code>
/// System::SharedPtr<Aspose::Pdf::Facades::PdfConverter> converter = System::MakeObject<Aspose::Pdf::Facades::PdfConverter>();
/// converter->BindPdf(L"D:\\Test\\test.pdf");
/// converter->DoConvert();
/// converter->SaveAsTIFFClassF(L"D:\\Test\\test.tiff");
/// </code>
/// </example>

PDF to PNG:

/// <summary>
/// Saves image to file with the givin image format.
/// </summary>
/// <param name="outputFile">The file path and name to save the image.</param>
/// <param name="format">The format of the image.</param>
/// <example>
/// 
/// <code>
/// System::SharedPtr<Aspose::Pdf::Facades::PdfConverter> converter = System::MakeObject<Aspose::Pdf::Facades::PdfConverter>();
/// converter->BindPdf(L"D:\\Test\\test.pdf");
/// converter->DoConvert();
/// System::String prefix = L"D:\\Test\\";
/// System::String suffix = L".png";
/// int32_t imageCount = 1;
/// while (converter->HasNextImage())
/// {
///     converter->GetNextImage(prefix + imageCount + suffix, System::Drawing::Imaging::ImageFormat::get_Png());
///     imageCount++;
/// }
/// </code>
/// </example>

Likewise, get_Bmp method of System::Drawing::Imaging::ImageFormat Class can be used to render a PDF document to BMP image.

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Thanks for your kind reply,
I was able to run the conversion for the suggested formats.
However I have one last question: is Aspose capable of managing PDF with layers? In that case, can you provide additional examples?

Thank you

@vsanelli

Thank you for your kind feedback.

We would like to update you that Aspose.PDF for C++ includes Aspose::Pdf::Layer Class which represents a page layer, and Page Class includes Aspose::Pdf::Page::get_Layers method which can be used to add or remove layers.

In case you need any further assistance, please elaborate a little more that how do you want to manage a PDF document with layers so that we may investigate further to help you out.