Add, remove and read comments in PowerPoint PPT/PPTX presentations in Java: https://blog.aspose.com/2022/02/08/add-comments-in-powerpoint-ppt-in-java/
Last active
February 23, 2022 06:26
-
-
Save aspose-com-gists/d334a1c695c4cc3640fe93847cdf0103 to your computer and use it in GitHub Desktop.
Add or Remove Comments in PowerPoint PPT/PPTX 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
// Create or load presentation | |
Presentation presentation = new Presentation("presentation.pptx"); | |
try { | |
// Add an empty slide or get reference of an existing slide | |
presentation.getSlides().addEmptySlide(presentation.getLayoutSlides().get_Item(0)); | |
// Add an author | |
ICommentAuthor author = presentation.getCommentAuthors().addAuthor("Usman", "UA"); | |
// Set the position for comments | |
Point2D.Float point = new Point2D.Float(0.2f, 0.2f); | |
// Add slide comment on first slide | |
author.getComments().addComment("Hello, this is slide comment", presentation.getSlides().get_Item(0), point, new Date()); | |
// Save presentation | |
presentation.save("add-comment.pptx", SaveFormat.Pptx); | |
} finally { | |
if (presentation != null) | |
presentation.dispose(); | |
} |
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
// Create or load presentation | |
Presentation presentation = new Presentation("presentation.pptx"); | |
try { | |
// Add an empty slide or get reference of an existing slide | |
presentation.getSlides().addEmptySlide(presentation.getLayoutSlides().get_Item(0)); | |
// Add an author | |
ICommentAuthor author = presentation.getCommentAuthors().addAuthor("Usman", "UA"); | |
// Set the position for comments | |
Point2D.Float point = new Point2D.Float(0.2f, 0.2f); | |
// Add slide comment on first slide | |
IComment comment = author.getComments().addComment("Hello, this is slide comment", presentation.getSlides().get_Item(0), point, new Date()); | |
// Add reply comment | |
IComment subReply = author.getComments().addComment("This is the reply to the comment.", presentation.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date()); | |
subReply.setParentComment(comment); | |
// Add reply comment | |
IComment reply2 = author.getComments().addComment("This is second reply.", presentation.getSlides().get_Item(0), new Point2D.Float(10, 10), new Date()); | |
reply2.setParentComment(comment); | |
// Save presentation | |
presentation.save("add-comment-reply.pptx", SaveFormat.Pptx); | |
} finally { | |
if (presentation != null) | |
presentation.dispose(); | |
} |
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
// Load presentation | |
Presentation presentation = new Presentation("add-comment.pptx"); | |
try { | |
// Loop through authors | |
for (ICommentAuthor commentAuthor : presentation.getCommentAuthors()) | |
{ | |
// Access each author | |
CommentAuthor author = (CommentAuthor) commentAuthor; | |
// Loop through author's comments | |
for (IComment comment1 : author.getComments()) | |
{ | |
// Read comment | |
Comment comment = (Comment) comment1; | |
System.out.println("ISlide :" + comment.getSlide().getSlideNumber() + " has comment: " + comment.getText() + | |
" with Author: " + comment.getAuthor().getName() + " posted on time :" + comment.getCreatedTime() + "\n"); | |
} | |
} | |
} finally { | |
if (presentation != null) | |
presentation.dispose(); | |
} |
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
// Load presentation | |
Presentation presentation = new Presentation("add-comment.pptx"); | |
try { | |
// Get first slide | |
ISlide slide = presentation.getSlides().get_Item(0); | |
// Get comments | |
IComment[] comments = slide.getSlideComments(null); | |
// Remove desired comment using index | |
comments[0].remove(); | |
// Save presentation | |
presentation.save("remove-comments.pptx", SaveFormat.Pptx); | |
} finally { | |
if (presentation != null) | |
presentation.dispose(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment