Save Presentation - C++ PowerPoint Library

The article here explains how to save presentations.

The Presentation class holds a presentation’s content. Whether creating a presentation from scratch or modifying an existing one, when finished, you want to save the presentation. With Aspose.Slides for C++, it can be saved as a file or stream. This article explains how to save a presentation in different ways:

Save Presentation to File

Save a presentation to files by calling the Presentation class Save method. Simply pass the file name and save format to the Save method. The examples that follow show how to save a presentation with Aspose.Slides for C++.

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
const String outPath = u"../out/SaveToFile_out.ppt";
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//pres->get_ProtectionManager()->Encrypt(u"pass");
//...do some work here..
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Save Presentation to Stream

It is possible to save a presentation to a stream by passing an output stream to the Presentation class Save method. There are many types of streams to which a presentation can be saved. In the below example we have created a new Presentation file, add text in shape and Save the presentation to the stream.

const String outPath = u"../out/Save_As_Stream_out.pptx";
SharedPtr<Presentation> pres = MakeObject<Presentation>();
SharedPtr<IAutoShape> shape = pres->get_Slides()->idx_get(0)->get_Shapes()->AddAutoShape(Aspose::Slides::ShapeType::Rectangle, 200, 200, 200, 200);
/// Load the video file to stream
System::SharedPtr<System::IO::Stream> stream = System::MakeObject<System::IO::FileStream>(outPath, System::IO::FileMode::Create);
pres->Save(stream, Aspose::Slides::Export::SaveFormat::Pptx);

Save Presentation with Predefined View Type

Aspose.Slides for C++ provides a facility to set the view type for the generated presentation when it is opened in PowerPoint through the ViewProperties class. The LastView property is used to set the view type by using the ViewType enumerator.

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
const String outPath = u"../out/SaveAsPredefinedViewType_out.ppt";
SharedPtr<Presentation> pres = MakeObject<Presentation>();
pres->get_ViewProperties()->set_LastView(Aspose::Slides::ViewType::SlideMasterView);
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Save Presentation to Strict Office Open XML Format

Aspose.Slides allows you to save the presentation in Strict Office Open XML format. For that purpose, it provides the PptxOptions class where you can set the Conformance property while saving the presentation file. If you set its value as Conformance.Iso29500_2008_Strict, then the output presentation file will be saved in Strict Office Open XML format.

The following sample code creates a presentation and saves it in the Strict Office Open XML Format. While calling the Save method for the presentation, the PptxOptions object is passed into it with the Conformance property set as Conformance.Iso29500_2008_Strict.

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
const String outPath = u"../out/SaveToStrictOpenXML_out.pptx";
//Instantiate Presentation object
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//Access first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Add an AutoShape of Rectangle type
SharedPtr<IAutoShape> ashp = slide->get_Shapes()->AddAutoShape(ShapeType::Rectangle, 150, 75, 150, 50);
//Setting options for strick XML
SharedPtr<PptxOptions> options = MakeObject<PptxOptions>();
options->set_Conformance(Conformance::Iso29500_2008_Strict);
//Save presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx, options);

Save a Presentation without Refreshing the Thumbnail

The IPptxOptions.set_RefreshThumbnail method allows you to control the generation of the thumbnail when saving a presentation in PPTX format:

  • When the value true is passed, the presentation thumbnail will be refreshed while saving. This is the default value.
  • When the value false is passed, the current thumbnail will be saved as is. If the presentation doesn’t have a thumbnail, no thumbnail will be generated.

In the code below, we saved the presentation to PPTX format without refreshing its thumbnail:

auto presentation = MakeObject<Presentation>(u"Sample.pptx");
    
auto pptxOptions = MakeObject<PptxOptions>();
pptxOptions->set_RefreshThumbnail(false);

presentation->Save(u"Sample_with_old_thumbnail.pptx", SaveFormat::Pptx, pptxOptions);
presentation->Dispose();

Save Progress Updates in Percentage

New IProgressCallback interface has been added to ISaveOptions interface and SaveOptions abstract class. IProgressCallback interface represents a callback object for saving progress updates in percentage.  

The following code snippets below shows how to use IProgressCallback interface:

const String templatePath = u"../templates/SamplePresentation.pptx";
const String outPath = u"../out/SamplePresentation_out.pptx";
auto presentation = System::MakeObject<Presentation>(templatePath);
System::SharedPtr<ISaveOptions> saveOptions = System::MakeObject<PdfOptions>();
System::SharedPtr<IProgressCallback> callBack = System::MakeObject<ExportProgressHandler>();
saveOptions->set_ProgressCallback(callBack);
presentation->Save(outPath, Aspose::Slides::Export::SaveFormat::Pdf, saveOptions);
class ExportProgressHandler : public IProgressCallback
{
public:
void Reporting(double progressValue)
{
System::Console::WriteLine(u"% completed", progressValue);
}
};