Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active October 7, 2023 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/44e9efda89a8f65b562c9d23c0e4af58 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/44e9efda89a8f65b562c9d23c0e4af58 to your computer and use it in GitHub Desktop.
Edit PowerPoint PPT/PPTX Presentations using C#
// 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