News Category

Comment and Note

Comment and Note (2)

When you are collaborating on a PowerPoint document with your team members, adding comments is the most effective way to give feedbacks or communicate the changes you need to make on a particular slide. Once a comment has been added, you may also need to edit or delete it later. This article will demonstrate how to programmatically add, change or delete comments in a PowerPoint Document using Spire.Presentation for Java.

Install Spire.Presentation for Java

First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>9.3.1</version>
    </dependency>
</dependencies>
    

Add a Comment to a Presentation Slide in Java

Spire.Presentation for Java offers the ISlide.addComment() method to add comments to a specified PowerPoint slide. The following are the steps to add a PowerPoint comment.

  • Initialize an instance of Presentation class.
  • Load a PowerPoint document using Presentation.loadFromFile() method.
  • Add the author of the comment using Presentation.getCommentAuthors().addAuthor() method.
  • Get a specified slide using Presentation.getSlides().get() method, and then add a comment to the slide using ISlide.addComment(ICommentAuthor author, java.lang.String text, java.awt.geom.Point2D position, java.util.Date dateTime) method.
  • Save the result document using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;
import java.awt.geom.Point2D;

public class AddComment {
    public static void main(String[] args) throws Exception{
        //Initialize an instance of Presentation class
        Presentation ppt = new Presentation();

        //Load a sample PowerPoint document
        ppt.loadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");

        //Add the author of the comment
        ICommentAuthor author = ppt.getCommentAuthors().addAuthor("E-iceblue", "Comment:");

        //Add a comment to the specified slide
        ppt.getSlides().get(0).addComment(author, "The first comment", new Point2D.Float(350, 170), new java.util.Date());

        //Save the result document
        ppt.saveToFile("AddComment.pptx", FileFormat.PPTX_2013);
        ppt.dispose();
    }
}

Java: Add, Change or Delete Comments in PowerPoint

Change a Comment in a Presentation Slide in Java

To update or modify the content of an existing comment, you can use the ISlide.getComments().setText() method. The following are the steps to change a PowerPoint comment.

  • Initialize an instance of Presentation class.
  • Load a PowerPoint document using Presentation.loadFromFile() method.
  • Get a specified slide using Presentation.getSlides().get() method.
  • Replace a specified comment in the slide using ISlide.getComments().setText() method.
  • Save the result document using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;

public class ReplaceComment {
    public static void main(String[] args) throws Exception{
        //Initialize an instance of Presentation class
        Presentation ppt = new Presentation();

        //Load a sample PowerPoint document
        ppt.loadFromFile("AddComment.pptx");

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Replace a specified comment in the slide
        slide.getComments()[0].setText("Summary of Spire.Presentation for Java functions");

        //Save the result document
        ppt.saveToFile("ReplaceComment.pptx", FileFormat.PPTX_2013);
        ppt.dispose();
    }
}

Java: Add, Change or Delete Comments in PowerPoint

Delete a Comment from a Presentation Slide in Java

Spire.Presentation for Java also allows you to remove comments from a specified slide using ISlide.deleteComment() method. The detailed steps are as follows.

  • Initialize an instance of Presentation class.
  • Load a PowerPoint document using Presentation.loadFromFile() method.
  • Get a specified slide using Presentation.getSlides().get() method.
  • Remove a specified comment from the slide using ISlide.deleteComment(Comment comment) method.
  • Save the result document using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;

public class DeleteComment {
    public static void main(String[] args) throws Exception{
        //Initialize an instance of Presentation class
        Presentation ppt = new Presentation();

        //Load a sample PowerPoint document
        ppt.loadFromFile("AddComment.pptx");

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Remove a specified comment from the slide
        slide.deleteComment(slide.getComments()[0]);

        //Save the result document
        ppt.saveToFile("DeleteComment.pptx", FileFormat.PPTX_2013);
        ppt.dispose();
    }
}

Java: Add, Change or Delete Comments in PowerPoint

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

When presenting a slideshow to an audience, you probably want to explain more than what appears on the slides. Adding speaker notes to your presentation is a great way to help you remember what needs to be said during the slideshow. In this article, you will learn how to add, read or delete speaker notes in PowerPoint in Java using Spire.Presentation for Java.

Install Spire.Presentation for Java

First of all, you're required to add the Spire.Presentation.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation</artifactId>
        <version>9.3.1</version>
    </dependency>
</dependencies>
    

Add Speaker Notes in PowerPoint in Java

The following are the main steps to add speaker notes to a PowerPoint document:

  • Create a Presentation instance and load a PowerPoint document using Presentation.loadFromFile() method.
  • Get the slide that you want to add speaker notes to using Presentation.getSlides().get(slideIndex) method.
  • Add a notes slide to the slide using ISlide.addNotesSlides() method.
  • Create a ParagraphEx instance.
  • Set text for the paragraph through ParagraphEx.setText() method, then append the paragraph to the notes slide using NotesSlide.getNotesTextFrame().getParagraphs().append() method.
  • Save the result document using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.*;

public class AddSpeakerNotes {
    public static void main(String []args) throws Exception {
        //Load a PowerPoint document
        Presentation ppt = new Presentation();
        ppt.loadFromFile("Sample.pptx");

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);
        //Add a notes slide
        NotesSlide notesSlide = slide.addNotesSlide();

        //Add a paragraph to the notes slide
        ParagraphEx paragraph = new ParagraphEx();
        paragraph.setText("Tips for making effective presentations:");
        notesSlide.getNotesTextFrame().getParagraphs().append(paragraph);

        //Add a paragraph to the notes slide
        paragraph = new ParagraphEx();
        paragraph.setText("Use the slide master feature to create a consistent and simple design template.");
        notesSlide.getNotesTextFrame().getParagraphs().append(paragraph);

        //Add a paragraph to the notes slide
        paragraph = new ParagraphEx();
        paragraph.setText("Simplify and limit the number of words on each screen.");
        notesSlide.getNotesTextFrame().getParagraphs().append(paragraph);

        //Add a paragraph to the notes slide
        paragraph = new ParagraphEx();
        paragraph.setText("Use contrasting colors for text and background.");
        notesSlide.getNotesTextFrame().getParagraphs().append(paragraph);

        //Set the bullet type and bullet style for specific paragraphs on the notes slide 
        for (int i = 1; i < notesSlide.getNotesTextFrame().getParagraphs().getCount();i++)
        {
            notesSlide.getNotesTextFrame().getParagraphs().get(i).setBulletType(TextBulletType.NUMBERED);
            notesSlide.getNotesTextFrame().getParagraphs().get(i).setBulletStyle(NumberedBulletStyle.BULLET_ARABIC_PERIOD);
        }

        //Save the result document
        ppt.saveToFile("SpeakerNotes.pptx", FileFormat.PPTX_2013);
    }
}

Java: Add, Read or Delete Speaker Notes in PowerPoint

Read Speaker Notes in PowerPoint in Java

The following are the steps to read the speaker notes on a PowerPoint slide:

  • Create a Presentation instance and load the PowerPoint document using Presentation.loadFromFile() method.
  • Get the slide that you want to read speaker notes from using Presentation.getSlides().get(slideIndex) method.
  • Get the notes slide from the slide using ISlide.getNotesSlide() method.
  • Get the speaker notes from the notes slide using NotesSlide.getNotesTextFrame().getText() method.
  • Create a StringBuilder instance.
  • Append the speaker notes to the string builder, then write them into a .txt file.
  • Java
import com.spire.presentation.ISlide;
import com.spire.presentation.NotesSlide;
import com.spire.presentation.Presentation;

import java.io.FileWriter;

public class ReadSpeakerNotes {
    public static void main(String []args) throws Exception {
        //Load the PowerPoint document
        Presentation ppt = new Presentation();
        ppt.loadFromFile("SpeakerNotes.pptx");

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);

        //Get the notes slide from the first slide
        NotesSlide notesSlide = slide.getNotesSlide();
        //Get the speaker notes from the notes slide
        String notes = notesSlide.getNotesTextFrame().getText();

        //Create a StringBuilder instance
        StringBuilder sb = new StringBuilder();
        //Append the speaker notes to the string builder
        sb.append(notes + "\n");

        //Save the speaker notes to a .txt file
        FileWriter writer = new FileWriter("SpeakerNotes.txt");
        writer.write(sb.toString());
        writer.flush();
        writer.close();
    }
}

Java: Add, Read or Delete Speaker Notes in PowerPoint

Delete Speaker Notes in PowerPoint in Java

The following are the steps to delete speaker notes from a PowerPoint slide:

  • Create a Presentation instance and load the PowerPoint document using Presentation.loadFromFile() method.
  • Get the slide that you want to delete speaker notes from using Presentation.getSlides().get(slideIndex) method.
  • Get the notes slide from the slide using ISlide.getNotesSlide() method.
  • Remove a specific speaker note from the notes slide using NotesSlide.getNotesTextFrame().getParagraphs().removeAt(paragraphIndex) method or remove all the speaker notes from the notes slide using NotesSlide.getNotesTextFrame().getParagraphs().clear() method.
  • Save the result document using Presentation.saveToFile() method.
  • Java
import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.NotesSlide;
import com.spire.presentation.Presentation;

public class DeleteSpeakerNotes {
    public static void main(String []args) throws Exception {
        //Load the PowerPoint document
        Presentation ppt = new Presentation();
        ppt.loadFromFile("SpeakerNotes.pptx");

        //Get the first slide
        ISlide slide = ppt.getSlides().get(0);
        //Get the notes slide from the slide
        NotesSlide notesSlide = slide.getNotesSlide();

        //Remove a specific speaker note from notes slide
        notesSlide.getNotesTextFrame().getParagraphs().removeAt(1);

        //Remove all the speaker notes from notes slide
        notesSlide.getNotesTextFrame().getParagraphs().clear();

        //Save the result document
        ppt.saveToFile("DeleteSpeakerNotes.pptx", FileFormat.PPTX_2013);
    }
}

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.