Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/c9a23c4792df46debc940fd874fb3d25 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/c9a23c4792df46debc940fd874fb3d25 to your computer and use it in GitHub Desktop.
Edit PowerPoint Files Using Java Library
import com.groupdocs.editor.cloud.api.EditorApi;
import com.groupdocs.editor.cloud.model.*;
import com.groupdocs.editor.cloud.model.requests.*;
import java.nio.file.Files;
import java.nio.file.Paths;
public class PowerPointEditExample {
public static void main(String[] args) {
// Replace with your actual credentials
String clientId = "YOUR_CLIENT_ID";
String clientSecret = "YOUR_CLIENT_SECRET";
// Initialize the API client
EditorApi editorApi = new EditorApi(clientId, clientSecret);
try {
// 1. Upload the original PPTX file
byte[] fileBytes = Files.readAllBytes(Paths.get("input.pptx"));
UploadResult uploadResult = editorApi.uploadFile("input.pptx", fileBytes);
// 2. Load the document for editing
LoadResult loadResult = editorApi.load(new LoadRequest(uploadResult.getPath()));
// 3. Replace placeholder text
ReplaceTextRequest replaceText = new ReplaceTextRequest(
loadResult.getDocumentId(),
"PLACEHOLDER_TITLE",
"Quarterly Report 2026"
);
editorApi.replaceText(replaceText);
// 4. Insert a new image into the first slide
byte[] imageBytes = Files.readAllBytes(Paths.get("chart.png"));
ReplaceImageRequest replaceImage = new ReplaceImageRequest(
loadResult.getDocumentId(),
"placeholder_image.png",
imageBytes
);
editorApi.replaceImage(replaceImage);
// 5. Save the edited presentation as PPTX
SaveResult saveResult = editorApi.save(new SaveRequest(
loadResult.getDocumentId(),
SaveOptions.PPTX
));
// 6. Write the edited file to disk
Files.write(Paths.get("edited.pptx"), saveResult.getFileContent());
System.out.println("Presentation edited and saved successfully.");
} catch (Exception e) {
System.err.println("Error during PowerPoint editing: " + e.getMessage());
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment