In PowerPoint presentations, the comments are used to write the feedback about the content in the slides. While manipulating PowerPoint PPT/PPTX presentations, you may need to add comments programmatically. In this article, you will learn how to add comments to PowerPoint PPT slides in Java. Moreover, we will cover how to read or remove slide comments and add their replies.
- Java API to Work with Comments in PowerPoint
- Add Comments in PowerPoint Slides
- Add Comment Replies in PPT Slides
- Read Comments from Slides
- Remove Comments from Slides
Java API to Work with Comments in PowerPoint
Aspose.Slides for Java is a popular presentation manipulation API that lets you create and modify PowerPoint PPT/PPTX files. We will use this API to manipulate comments in PowerPoint presentations. You can either download API’s JAR or install it using the following Maven configurations.
Repository:
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-slides</artifactId>
<version>22.2</version>
<classifier>jdk16</classifier>
</dependency>
Add Comments to PowerPoint PPT Slides in Java
In PowerPoint presentations, every comment is attached to a particular author. Whereas, each comment contains some additional information such as time of creation, slide where it is added, and its position. The following are the steps to add comments to a PPT slide in Java.
- First, load the presentation file or create a new one using Presentation class.
- Add a new author using Presentation.getCommentAuthors().addAuthor(String, String) method.
- Get reference of the newly created author in an object.
- Define the position of the comment.
- Add comment using ICommentAuthor.getComments().addComment(String, ISlide, Point2D.Float, Date) method.
- Finally, save presentation using Presentation.save(String, SaveFormat) method.
The following code sample shows how to add comments to PPT slides in Java.
The following is the screenshot of the comment we have added using the above code sample.
Add Comment Replies in PPT Slides in Java
Aspose.Slides also allows you to add replies to the comments. A reply itself is a comment which appears as a child of an existing comment. So let’s see how to add replies to comments in PowerPoint PPT slides in Java.
- First, load the presentation file or create a new one using Presentation class.
- Add a new author using Presentation.getCommentAuthors().addAuthor(String, String) method.
- Add comment using ICommentAuthor.getComments().addComment(String, ISlide, Point2D.Float, Date) method and get returned object.
- Insert another comment in the same way and get its reference in an object.
- Set parent of the second comment using IComment.setParentComment(IComment) method.
- Finally, save presentation using Presentation.save(String, SaveFormat) method.
The following code sample shows how to add replies to comments in a PPTX presentation in Java.
The following screenshot shows the output of the above code sample.
Read Comments in PPT Slides in Java
Using Aspose.Slides, you can also read comments of a particular author or all the authors. The following are the steps to read comments in PPT slides in Java.
- Load the presentation file using Presentation class.
- Loop through the list of authors using Presentation.getCommentAuthors() collection.
- For each author, loop through its comments using ICommentAuthor.getComments() method.
- Read and print comment details.
The following code sample shows how to read comments in PPT slides in Java.
Remove Comments from PowerPoint PPT in Java
In the previous section, you have seen how to read a comment by accessing it from the comments collection. Similarly, you can remove a comment after getting its reference. The following code sample shows how to remove comments in PowerPoint presentations in Java.
Get a Free License
You can use Aspose.Slides for Java without evaluation limitations by requesting a temporary license.
Conclusion
In this article, you have learned how to add comments in PowerPoint PPT slides in Java. Moreover, we have covered how to add replies to the comments programmatically. In the end, we have demonstrated how to read or remove comments from PPT slides. You can visit the documentation to explore more about Aspose.Slides for Java. Also, you can post your queries to our forum.