Related Article(s):
Last active
October 7, 2023 04:24
-
-
Save GroupDocsGists/44e9efda89a8f65b562c9d23c0e4af58 to your computer and use it in GitHub Desktop.
Edit PowerPoint PPT/PPTX Presentations using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Edit PPT/PPTX presenatations in C# using GroupDocs presentation editing and automation API | |
using (FileStream fs = File.OpenRead("path/presentation.pptx")) | |
{ | |
// Load Presentation | |
Options.PresentationLoadOptions loadOptions = new PresentationLoadOptions(); | |
loadOptions.Password = "P@$$w0Rd"; | |
// Edit Presentation | |
using (Editor editor = new Editor(delegate { return fs; }, delegate { return loadOptions; })) | |
{ | |
Options.PresentationEditOptions editOptions = new PresentationEditOptions(); | |
editOptions.SlideNumber = 0; // 1st slide | |
editOptions.ShowHiddenSlides = true; | |
using (EditableDocument beforeEdit = editor.Edit(editOptions)) | |
{ | |
string originalContent = beforeEdit.GetContent(); | |
List<IHtmlResource> allResources = beforeEdit.AllResources; | |
string editedContent = originalContent.Replace("documents", "presentation"); | |
// Save Presentation | |
using (EditableDocument afterEdit = EditableDocument.FromMarkup(editedContent, allResources)) | |
{ | |
Options.PresentationSaveOptions saveOptions = new PresentationSaveOptions(PresentationFormats.Pptm); | |
saveOptions.Password = "new_pa$$word"; | |
using (FileStream outputStream = File.Create("path/edited-presentation.pptx")) | |
{ | |
editor.Save(afterEdit, outputStream, saveOptions); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment