Working with Comments and Speaker Notes — Aspose.Slides FOSS for Java

This guide shows how to add and read threaded comments and speaker notes in PPTX presentations using Aspose.Slides FOSS for Java. Two annotation types are supported: threaded slide comments (visible in review mode) and speaker notes (visible in Presenter View and the Notes pane).


Threaded Comments

Comments are attached to a slide and associated with an author. The prs.getCommentAuthors() collection manages all authors; each author has a getComments() collection for adding and reading comments.

Add a Comment

Call prs.getCommentAuthors().addAuthor() to create an author, then call author.getComments().addComment() with the slide, text, position, and timestamp:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.drawing.PointF;
import org.aspose.slides.foss.export.SaveFormat;
import java.time.LocalDateTime;

try (Presentation prs = new Presentation()) {
    // Create a comment author with initials
    var author = prs.getCommentAuthors().addAuthor("Jane Smith", "JS");

    var slide = prs.getSlides().get(0);

    // Add a comment at position (2.0, 2.0) centimeters from the slide top-left
    author.getComments().addComment(
        "Please review the figures on this slide",
        slide,
        new PointF(2.0f, 2.0f),
        LocalDateTime.now()
    );

    prs.save("commented.pptx", SaveFormat.PPTX);
}

The PointF position is in centimeters from the top-left corner of the slide (internally stored as EMU; 1 cm = 360,000 EMU). Multiple comments can be added to the same slide by calling addComment() again.

Multiple Authors and Comments

Create separate authors for each reviewer and add independent comments from different authors to the same slide:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.drawing.PointF;
import org.aspose.slides.foss.export.SaveFormat;
import java.time.LocalDateTime;

try (Presentation prs = new Presentation()) {
    var author1 = prs.getCommentAuthors().addAuthor("Alice Brown", "AB");
    var author2 = prs.getCommentAuthors().addAuthor("Bob Davis", "BD");

    var slide = prs.getSlides().get(0);

    author1.getComments().addComment("Initial draft", slide, new PointF(1.0f, 1.0f), LocalDateTime.now());
    author2.getComments().addComment("Approved", slide, new PointF(3.0f, 1.0f), LocalDateTime.now());

    prs.save("multi-author.pptx", SaveFormat.PPTX);
}

Read Comments from an Existing File

Iterate prs.getCommentAuthors() to access each author, then iterate author.getComments() to read the comment text:

import org.aspose.slides.foss.Presentation;

try (Presentation prs = new Presentation("commented.pptx")) {
    for (int a = 0; a < prs.getCommentAuthors().size(); a++) {
        var author = prs.getCommentAuthors().get(a);
        System.out.println("Author: " + author.getName() + " (" + author.getInitials() + ")");
        for (int c = 0; c < author.getComments().size(); c++) {
            var comment = author.getComments().get(c);
            System.out.println("  " + comment.getText());
        }
    }
}

Speaker Notes

Speaker notes are stored on a per-slide basis via a NotesSlide object. Access it through slide.getNotesSlideManager().

Add Speaker Notes to a Slide

Call slide.getNotesSlideManager().addNotesSlide() to create a notes slide, then set the text on notes.getNotesTextFrame():

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.export.SaveFormat;

try (Presentation prs = new Presentation()) {
    var slide = prs.getSlides().get(0);
    slide.getShapes().addAutoShape(ShapeType.RECTANGLE, 50, 50, 400, 200);

    // Create the notes slide and set text
    var notes = slide.getNotesSlideManager().addNotesSlide();
    notes.getNotesTextFrame().setText(
        "Mention the Q3 revenue increase on this slide. Emphasize the 24% growth."
    );

    prs.save("with-notes.pptx", SaveFormat.PPTX);
}

Simpler Notes Example

The call to addNotesSlide() works the same regardless of what shapes are on the slide — add a shape, then create the notes:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.export.SaveFormat;

try (Presentation prs = new Presentation()) {
    var slide = prs.getSlides().get(0);
    slide.getShapes().addAutoShape(ShapeType.RECTANGLE, 100, 100, 500, 250)
         .addTextFrame("Main Content");

    var notes = slide.getNotesSlideManager().addNotesSlide();
    notes.getNotesTextFrame().setText("These are the speaker notes for this slide.");

    prs.save("notes.pptx", SaveFormat.PPTX);
}

Check Whether a Notes Slide Already Exists

getNotesSlideManager().getNotesSlide() returns null if no notes slide has been created yet:

import org.aspose.slides.foss.Presentation;

try (Presentation prs = new Presentation("existing.pptx")) {
    for (int i = 0; i < prs.getSlides().size(); i++) {
        var slide = prs.getSlides().get(i);
        var existingNotes = slide.getNotesSlideManager().getNotesSlide();
        if (existingNotes != null) {
            String text = existingNotes.getNotesTextFrame().getText();
            System.out.println("Slide " + (i + 1) + " notes: " + text);
        } else {
            System.out.println("Slide " + (i + 1) + ": no notes");
        }
    }
}

Add Notes to Multiple Slides

Iterate prs.getSlides() and call addNotesSlide() on each slide to attach a speaker note from an array of prepared text strings:

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ShapeType;
import org.aspose.slides.foss.export.SaveFormat;

String[] noteTexts = {
    "Opening remarks: introduce the agenda.",
    "Key metrics: emphasize Q4 results.",
    "Closing: call to action.",
};

try (Presentation prs = new Presentation()) {
    // Add slides 2 and 3
    var layout = prs.getSlides().get(0).getLayoutSlide();
    prs.getSlides().addEmptySlide(layout);
    prs.getSlides().addEmptySlide(layout);

    for (int i = 0; i < prs.getSlides().size(); i++) {
        var slide = prs.getSlides().get(i);
        slide.getShapes().addAutoShape(ShapeType.RECTANGLE, 50, 50, 600, 300)
             .addTextFrame("Slide " + (i + 1));
        var n = slide.getNotesSlideManager().addNotesSlide();
        n.getNotesTextFrame().setText(noteTexts[i]);
    }

    prs.save("all-notes.pptx", SaveFormat.PPTX);
}

See Also

 English