This example demonstrates standard open-edit-save cycle with Presentation documents, using different options on every step.
Introduction
Presentation documents are presented by many formats: PPT, PPTX, PPTM, PPS(X/M), POT(X/M) and other, which are supported by GroupDocs.Editor as a separate format family among all others. Same like for all other family formats, Presentation family has its own load, edit and save options. Presentation format has significant distinction from the WordProcessing and all textual formats, and at the same time big similarity with Spreadsheet formats, — it has no pages, but instead of pages it has slides (like Spreadsheet has tabs). Like tabs in Spreadsheets, slides in Presentations are completely separate one from each other and has no valid representation in HTML markup, so the only way to edit slides is to edit them separately, one slide per one editing procedure.
As a result, a Presentation document with multiple slides is loaded into the Editor class. Then, in order to open document for editing by calling an Editor.Edit method, user should select desired slide for editing by specifying its index in the PresentationEditOptions. As a result, user will obtain an instance of EditableDocument class, that holds that edited slide. For editing another slide, user should perform another call of the Editor.Edit method with another slide index, and obtain a new instance of EditableDocument class. Finally, when saving edited slides back to Presentation format, user should save every EditableDocument instance separately.
Like all Office OOXML formats, Presentation documents can be encrypted with password. GroupDocs.Editor supports opening password-protected Presentation documents (password should be specified in the PresentationLoadOptions) and creating password-protected documents (password should be specified in the PresentationSaveOptions).
Loading Presentation for editing
First step for edit a document is to load it. In order to load presentation to the Editor class, user should use the PresentationLoadOptions class. It is not necessary in some general cases — even without PresentationLoadOptions the GroupDocs.Editor is able to recognize presentation format and apply appropriate default load options automatically. But when presentation is encoded, the PresentationLoadOptions is the only way to set a password and load the document properly.
SlideNumber is a zero-based index of a slide, that allows to specify and select one particular slide from a presentation to edit. If lesser then 0, the first slide will be selected (same as SlideNumber = 0). If greater then amount of all slides in presentation, the last slide will be selected. If input presentation contains only single slide, this option will be ignored, and this single slide will be edited. By default is 0, that implies first slide for edit.
ShowHiddenSlides is a boolean flag, which specifies whether the hidden slides should be included or not. Default is false — hidden slides are not shown and exception will be thrown while trying to edit them. So, if input Presentation has 5 slides, where 2nd is hidden, user has specified SlideNumber = 1 (2nd slide) and simultaneously ShowHiddenSlides = false, the InvalidOperationException will be thrown. From this short example it can be seen, that the indexes of the hidden slides are not flopped in but instead are denied — when trying to access them, the InvalidOperationException occurs.
Code example below demonstrates all options, described above. Let’s assume, that Presentation document with at least 3 slides is already loaded into the Editor class.
//parameterless overload is used => default PresentationEditOptions is applied, which means 1st slideEditableDocumentfirstSlide=editor.Edit();PresentationEditOptionseditOptions2=newPresentationEditOptions();editOptions2.SlideNumber=1;//index is 0-based, so this is 2nd slideEditableDocumentsecondSlide=editor.Edit(editOptions2);PresentationEditOptionseditOptions3=newPresentationEditOptions();editOptions3.SlideNumber=2;//index is 0-based, so this is 3rd slideeditOptions3.ShowHiddenSlides=true;//if 3rd slide is hidden, it will be opened anywayEditableDocumentthirdSlide=editor.Edit(editOptions3);
Save Presentation after edit
PresentationSaveOptions class is designed for saving the edited Presentation documents. This class has one constructor, which has one parameter — a Presentation format, in which the output document should be saved. This output format is represented by the PresentationFormats struct. After creating an instance, output format can be obtained or modified later, through the OutputFormat property. This is the only parameter, which is necessary for saving the document: all others are optional and may be omitted.
Along with format, user is able to specify a password through the Password string property — in this case output document will be encoded and protected with this password. By default password is not set, which implies that output document will be unprotected. This is shown in example below, where it is supposed that a user has an EditableDocument instance with edited slide.
PresentationSaveOptionssaveOptions=newPresentationSaveOptions(PresentationFormats.Pptm);saveOptions.Password="new password";EditableDocumentafterEdit=/* obtain it from somewhere */;FileStreamoutputStream=/* obtain it from somewhere */;//saving edited slide to specified stream in PPTM format and with password encodingeditor.Save(afterEdit,outputStream,saveOptions);
Starting from version 20.4, PresentationSaveOptions class contains two new properties — SlideNumber and InsertAsNewSlide, — which are highly coupled together. These properties allow to insert edited slide into existing presentation instead of creating new presentation with single edited slide, which remains the default behavior. They are explained in detail in separate article.