Convert PPT, PPTX, and ODP to JPG in C++

Overview

Converting PowerPoint and OpenDocument presentations to JPG images helps with sharing slides, optimizing performance, and embedding content into websites or applications. Aspose.Slides for C++ allows you to transform PPTX, PPT, and ODP files into high-quality JPEG images. This guide explains different methods for conversion.

With these features, it’s easy to implement your own presentation viewer and create a thumbnail for every slide. This may be useful if you want to protect presentation slides from copying or demonstrate the presentation in read-only mode. Aspose.Slides allows you to convert the whole presentation or a specific slide into image formats.

Convert Presentation Slides to JPG Images

Here are the steps to convert a PPT, PPTX, or ODP file to JPG:

  1. Create an instance of the Presentation class.
  2. Get the slide object of the ISlide type from the presentation’s slide collection.
  3. Create an image of the slide using the ISlide.GetImage method.
  4. Call the IImage.Save method on the image object. Pass the output file name and image format as arguments.
float scaleX = 1.0f;
float scaleY = scaleX;

auto presentation = MakeObject<Presentation>(u"PowerPoint-Presentation.ppt");

for (auto&& slide : presentation->get_Slides())
{
    // Create a slide image of the specified scale.
    auto image = slide->GetImage(scaleX, scaleY);

    // Save the image to disk in JPEG format.
    auto fileName = String::Format(u"Slide_{0}.jpg", slide->get_SlideNumber());
    image->Save(fileName, ImageFormat::Jpeg);

    image->Dispose();
}

presentation->Dispose();

Convert Slides to JPG with Customized Dimensions

To change the dimensions of the resulting JPG images, you can set the image size by passing it into the ISlide.GetImage(Size) method. This allows you to generate images with specific width and height values, ensuring that the output meets your requirements for resolution and aspect ratio. This flexibility is particularly useful when generating images for web applications, reports, or documentation, where precise image dimensions are required.

Size imageSize(1200, 800);

auto presentation = MakeObject<Presentation>(u"PowerPoint-Presentation.pptx");

for (auto&& slide : presentation->get_Slides())
{
    // Create a slide image of the specified size.
    auto image = slide->GetImage(imageSize);

    // Save the image to disk in JPEG format.
    auto fileName = System::String::Format(u"Slide_{0}.jpg", slide->get_SlideNumber());
    image->Save(fileName, ImageFormat::Jpeg);

    image->Dispose();
}

presentation->Dispose();

Render Comments when Saving Slides as Images

Aspose.Slides for C++ provides a feature that allows you to render comments on a presentation’s slides when converting them into JPG images. This functionality is particularly useful for preserving annotations, feedback, or discussions added by collaborators in PowerPoint presentations. By enabling this option, you ensure that comments are visible in the generated images, making it easier to review and share feedback without needing to open the original presentation file.

Let’s say we have a presentation file, “sample.pptx,” with a slide that contains comments:

The slide with comments

The following C++ code converts the slide to a JPG image while preserving the comments:

float scaleX = 2.0f;
float scaleY = scaleX;

auto presentation = MakeObject<Presentation>(u"sample.pptx");
{
    auto commentOptions = MakeObject<NotesCommentsLayoutingOptions>();
    commentOptions->set_CommentsPosition(CommentsPositions::Right);
    commentOptions->set_CommentsAreaWidth(200);
    commentOptions->set_CommentsAreaColor(Color::get_DarkOrange());

    // Set options for the slide comments.
    auto options = MakeObject<RenderingOptions>();
    options->set_SlidesLayoutOptions(commentOptions);

    // Convert the first slide to an image.
    auto image = presentation->get_Slide(0)->GetImage(options, scaleX, scaleY);
        
    image->Save(u"Slide_1.jpg", ImageFormat::Jpeg);
    image->Dispose();
}

presentation->Dispose();

The result:

The JPG image with comments

See also

See other options for converting PPT, PPTX, or ODP to images, such as:

Free Online PPTX to JPG Converter