Lucrul cu comentarii și note de vorbitor — Aspose.Slides FOSS pentru Java

Aspose.Slides FOSS for Java supports two types of annotations: comentarii în lanț pentru diapozitiv (vizibil în modul de revizuire) și note ale prezentatorului (vizibil în modul Prezentare și în panoul Note).


Comentarii în lanț

Comentariile sunt atașate unui diapozitiv și asociate cu un autor. Colecția prs.getCommentAuthors() colecție gestionează toți autorii; fiecare autor are o getComments() colecție pentru adăugarea și citirea comentariilor.

Adăugați un comentariu

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);
}

Poziția PointF poziția este în inci de la colțul stânga-sus al diapozitivului. Comentarii multiple pot fi adăugate aceluiași diapozitiv prin apelarea addComment() din nou.

Mai mulți autori și comentarii

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);
}

Citiți comentariile dintr-un fișier existent

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());
        }
    }
}

Note ale prezentatorului

Notele prezentatorului sunt stocate pe bază de diapozitiv printr-un NotesSlide obiect. Accesați-l prin slide.getNotesSlideManager().

Adăugați note de vorbitor la un diapozitiv

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);
}

Exemplu simplu de note

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);
}

Verificați dacă există deja un diapozitiv de note

getNotesSlideManager().getNotesSlide() returnează null dacă nu a fost încă creat niciun slide de note:

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");
        }
    }
}

Adăugați note la mai multe diapozitive

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);
}

Vezi și

 Română