Related Article(s):
Created
October 7, 2023 09:27
-
-
Save GroupDocsGists/d064e0aa892fbbf47b9b8b16f4f99803 to your computer and use it in GitHub Desktop.
Edit PowerPoint PPT/PPTX Presentations in Java
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 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