Πώς να προσθέσετε σχόλια σε PowerPoint με Java

Πώς να προσθέσετε σχόλια σε PowerPoint με Java

Το Aspose.Slides FOSS for Java υποστηρίζει νήματα σχολίων που είναι συνδεδεμένα σε μια διαφάνεια σε συγκεκριμένη θέση, ορατά στο παράθυρο Ανασκόπηση του PowerPoint.


Προαπαιτούμενα

<dependency>
  <groupId>org.aspose.slides.foss</groupId>
  <artifactId>aspose-slides-foss</artifactId>
  <version>1.0.0</version>
</dependency>

Προσθήκη σχολίου

Τα σχόλια ανήκουν σε ένα αντικείμενο συγγραφέα. Δημιουργήστε πρώτα έναν συγγραφέα, έπειτα προσθέστε σχόλια μέσω author.getComments():

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.ICommentAuthor;
import org.aspose.slides.foss.ICommentCollection;
import org.aspose.slides.foss.IComment;
import org.aspose.slides.foss.export.SaveFormat;
import org.aspose.slides.foss.drawing.PointF;
import java.time.LocalDateTime;

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

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

    // Add a comment at position (2.0, 2.0) from the slide top-left corner
    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);
}

Οι συντεταγμένες PointF καθορίζουν τη θέση του άγκυρου σχολίου. Πολλές κλήσεις στο addComment() δημιουργούν μια αλυσίδα νήματος σχολίων κάτω από τον ίδιο συγγραφέα.


Πολλαπλοί Συγγραφείς και Σχόλια

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.ICommentAuthor;
import org.aspose.slides.foss.ICommentCollection;
import org.aspose.slides.foss.IComment;
import org.aspose.slides.foss.export.SaveFormat;
import org.aspose.slides.foss.drawing.PointF;
import java.time.LocalDateTime;

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

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

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

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

Ανάγνωση Σχολίων από Υπάρχον Αρχείο

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.ICommentAuthor;
import org.aspose.slides.foss.ICommentCollection;
import org.aspose.slides.foss.IComment;
import org.aspose.slides.foss.export.SaveFormat;
import org.aspose.slides.foss.drawing.PointF;

try (Presentation prs = new Presentation("commented.pptx")) {
    for (int i = 0; i < prs.getCommentAuthors().size(); i++) {
        ICommentAuthor author = prs.getCommentAuthors().get(i);
        System.out.println("Author: " + author.getName()
            + " (" + author.getInitials() + ")");
        ICommentCollection comments = author.getComments();
        for (int j = 0; j < comments.size(); j++) {
            IComment comment = comments.get(j);
            System.out.println("  Slide " + comment.getSlide().getSlideNumber()
                + ": " + comment.getText());
        }
    }
}

Αφαίρεση σχολίου

import org.aspose.slides.foss.Presentation;
import org.aspose.slides.foss.ISlide;
import org.aspose.slides.foss.ICommentAuthor;
import org.aspose.slides.foss.ICommentCollection;
import org.aspose.slides.foss.IComment;
import org.aspose.slides.foss.export.SaveFormat;
import org.aspose.slides.foss.drawing.PointF;

try (Presentation prs = new Presentation("commented.pptx")) {
    ICommentAuthor author = prs.getCommentAuthors().get(0);
    if (author.getComments().size() > 0) {
        author.getComments().removeAt(0);
    }
    prs.save("cleaned.pptx", SaveFormat.PPTX);
}

Δείτε επίσης

 Ελληνικά