Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Created October 7, 2023 09:27
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/d064e0aa892fbbf47b9b8b16f4f99803 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/d064e0aa892fbbf47b9b8b16f4f99803 to your computer and use it in GitHub Desktop.
Edit PowerPoint PPT/PPTX Presentations in Java
// Edit PPT/PPTX presenatations in Java using GroupDocs presentation editing and automation API
// Load Presentation
PresentationLoadOptions loadOptions = new PresentationLoadOptions();
loadOptions.setPassword("P@$$w0Rd");
// Edit Presentation
Editor editor = new Editor(new FileInputStream("path/presentation.pptx"), loadOptions);
PresentationEditOptions editOptions = new PresentationEditOptions();
editOptions.setSlideNumber(0); //1st slide
editOptions.setShowHiddenSlides(true);
EditableDocument beforeEdit = editor.edit(editOptions);
String originalContent = beforeEdit.getContent();
List<IHtmlResource> allResources = beforeEdit.getAllResources();
String editedContent = originalContent.replace("document", "presentation");
// Save Presentation
EditableDocument afterEdit = EditableDocument.fromMarkup(editedContent, allResources);
PresentationSaveOptions saveOptions = new PresentationSaveOptions(PresentationFormats.Pptm);
saveOptions.setPassword("new_pa$$word");
editor.save(afterEdit, new ByteArrayOutputStream(), saveOptions);
try(OutputStream outputFile = new FileOutputStream("path/edited-presentation.pptx")) {
outputStream.writeTo(outputFile);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment