Converting PowerPoint presentations to images brings you multiple benefits. For example, it makes it easy for you to share the content with others who may not have access to PowerPoint software; it preserves the formatting of the original presentation, ensuring that the content appears exactly as intended; and it protects the content in the presentation from being edited or modified by others. In this article, you will learn how to convert a PowerPoint Presentation to different image formats in C++ using Spire.Presentation for C++.
- Convert PowerPoint Presentation to JPG or PNG Images
- Convert PowerPoint Presentation to JPG or PNG Images with Specific Size
- Convert PowerPoint Presentation to SVG Images
Install Spire.Presentation for C++
There are two ways to integrate Spire.Presentation for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.Presentation for C++ in a C++ Application
Convert PowerPoint Presentation to JPG or PNG Images in C++
Spire.Presentation for C++ offers the ISlide->SaveAsImage() method which enables you to convert the slides in a PowerPoint presentation to JPG or PNG images. The detailed steps are as follows:
- Initialize an instance of the Presentation class.
- Load a PowerPoint presentation using Presentation->LoadFromFile() method.
- Access the slide collection of the presentation using Presentation->GetSlides() method.
- Iterate through the slides in the collection.
- Save each slide to an image stream using ISlide->SaveAsImage() method.
- Save the image stream to a JPG or PNG file using Stream->Save() method.
- C++
#include "Spire.Presentation.o.h" using namespace Spire::Presentation; using namespace std; int main() { //Initialize an instance of the Presentation class Presentation* ppt = new Presentation(); //Load a PowerPoint presentation ppt->LoadFromFile(L"Sample.pptx"); //Get the slide collection of the presentation SlideCollection* slides = ppt->GetSlides(); //Iterate through the slides in the collection for (int i = 0; i < slides->GetCount(); i++) { ISlide* slide = slides->GetItem(i); //Save each slide to a PNG image Stream* image = slide->SaveAsImage(); image->Save(( L"Images\\ToImage_img_" + to_wstring(i) + L".png").c_str()); } ppt->Dispose(); delete ppt; }
Convert PowerPoint Presentation to JPG or PNG Images with Specific Size in C++
You can convert the slides in a PowerPoint presentation to JPG or PNG images with a specific size using ISlide->SaveAsImage(int width, int height) method. The detailed steps are as follows:
- Initialize an instance of the Presentation class.
- Load a PowerPoint presentation using Presentation->LoadFromFile() method.
- Access the slide collection of the presentation using Presentation->GetSlides() method.
- Iterate through the slides in the collection.
- Save each slide to an image stream using ISlide->SaveAsImage(int width, int height) method.
- Save the image stream to a JPG or PNG file using Stream->Save() method.
- C++
#include "Spire.Presentation.o.h" using namespace Spire::Presentation; using namespace std; int main() { //Initialize an instance of the Presentation class Presentation* ppt = new Presentation(); //Load a PowerPoint presentation ppt->LoadFromFile(L"Sample.pptx"); //Get the slide collection of the presentation SlideCollection* slides = ppt->GetSlides(); //Iterate through the slides in the collection for (int i = 0; i < slides->GetCount(); i++) { ISlide* slide = slides->GetItem(i); //Save each slide to a PNG image with a size of 600 x 400 pixels Stream* image = slide->SaveAsImage(600, 400); image->Save(( L"ImagesWithSpecificSize\\ToImage_img_" + to_wstring(i) + L".png").c_str()); } ppt->Dispose(); delete ppt; }
Convert PowerPoint Presentation to SVG Images in C++
To convert the slides in a PowerPoint presentation to SVG images, you can use the ISlide->SaveToSVG() method. The detailed steps are as follows:
- Initialize an instance of the Presentation class.
- Load a PowerPoint presentation using Presentation->LoadFromFile() method.
- Access the slide collection of the presentation using Presentation->GetSlides() method.
- Iterate through the slides in the collection.
- Save each slide to an SVG stream using ISlide->SaveToSVG() method.
- Save the SVG stream to an SVG file using Stream->Save() method.
- C++
#include "Spire.Presentation.o.h" using namespace Spire::Presentation; using namespace std; int main() { //Initialize an instance of the Presentation class Presentation* ppt = new Presentation(); //Load a PowerPoint presentation ppt->LoadFromFile(L"Sample.pptx"); //Get the slide collection of the presentation SlideCollection* slides = ppt->GetSlides(); //Set whether to retain notes while converting PowerPoint to SVG ppt->SetIsNoteRetained(true); //Iterate through the slides in the collection for (int i = 0; i < slides->GetCount(); i++) { ISlide* slide = slides->GetItem(i); //Save each slide to an SVG image Stream* svg = slide->SaveToSVG(); svg->Save((L"SvgImages\\ToSVG-" + to_wstring(i) + L".svg").c_str()); } ppt->Dispose(); delete ppt; }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.