DEV Community

CodeSharing
CodeSharing

Posted on

Add/ Read/ Delete Speaker Notes in PowerPoint Using Java

In PowerPoint documents, speaker notes can help people store the information they want to mention. During the presentation, speaker notes allow people to view the notes on their personal screen while other audience can only see the slides. This article will introduce how to add, read and delete speaker notes in a PowerPoint document using Free Spire.Presentation for Java.

Import jar dependency (2 Methods)
● Download the Free Spire.Presentation for Java and unzip it. Then add the Spire.Presentation.jar file to your project as dependency.

● You can also add the jar dependency to your maven project by adding the following configurations to the pom.xml.

<repositories>
        <repository>
            <id>com.e-iceblue</id>
            <name>e-iceblue</name>
            <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
        </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.presentation.free</artifactId>
        <version>3.9.0</version>
    </dependency>
</dependencies>
Enter fullscreen mode Exit fullscreen mode

Add Speaker Notes:

import com.spire.presentation.*;

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

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

        //Add a paragraph to the note slide
        ParagraphEx paragraph = new ParagraphEx();
        paragraph.setText("The poem's main theme:");
        notesSlide.getNotesTextFrame().getParagraphs().append(paragraph);


        //Add a paragraph to the note slide
        paragraph = new ParagraphEx();
        paragraph.setText("The poem's title suggests that someone has literally died, and the speaker also asks for “coffin” and “mourners.”");
        notesSlide.getNotesTextFrame().getParagraphs().append(paragraph);
        //Set the bullet type and style for the paragraph
        notesSlide.getNotesTextFrame().getParagraphs().get(1).setBulletType(TextBulletType.NUMBERED);
        notesSlide.getNotesTextFrame().getParagraphs().get(1).setBulletStyle(NumberedBulletStyle.BULLET_ARABIC_PERIOD);

        //Add a paragraph to the note slide
        paragraph = new ParagraphEx();
        paragraph.setText(" The poem insists that the world doesn’t stop to grieve with the speaker.");
        notesSlide.getNotesTextFrame().getParagraphs().append(paragraph);
        //Set the bullet type and style for the paragraph
        notesSlide.getNotesTextFrame().getParagraphs().get(2).setBulletType(TextBulletType.NUMBERED);
        notesSlide.getNotesTextFrame().getParagraphs().get(2).setBulletStyle(NumberedBulletStyle.BULLET_ARABIC_PERIOD);

        //Add a paragraph to the note slide
        paragraph = new ParagraphEx();
        paragraph.setText(" Examples: the stars keep shining, the clocks keep ticking, and the dogs keep barking, much to the speaker’s frustration.");
        notesSlide.getNotesTextFrame().getParagraphs().append(paragraph);
        //Set the bullet and style type for the paragraph
        notesSlide.getNotesTextFrame().getParagraphs().get(3).setBulletType(TextBulletType.NUMBERED);
        notesSlide.getNotesTextFrame().getParagraphs().get(3).setBulletStyle(NumberedBulletStyle.BULLET_ARABIC_PERIOD);

        //Save the document
        ppt.saveToFile("SpeakerNotes.pptx", FileFormat.PPTX_2013);
    }
}
Enter fullscreen mode Exit fullscreen mode

Alt Text

Read Speaker Notes:

import com.spire.presentation.*;

import java.io.FileWriter;

public class ReadNotes  {
    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 content of notes from note slide
        StringBuilder buffer = new StringBuilder();
        String notes = slide.getNotesSlide().getNotesTextFrame().getText();
        buffer.append(notes);

        //Save to .txt file
        FileWriter writer = new FileWriter("SpeakerNotes.txt");
        writer.write(buffer.toString());
        writer.flush();
        writer.close();

    }
}
Enter fullscreen mode Exit fullscreen mode

Alt Text

Delete Speaker Notes:

import com.spire.presentation.*;

public class DeleteNotes {
    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);

        //Delete all speaker notes from the note slide
        slide.getNotesSlide().getNotesTextFrame().getParagraphs().clear();

        //Save the document
        ppt.saveToFile("DeleteSpeakerNotes.pptx", FileFormat.PPTX_2013);
    }
}
Enter fullscreen mode Exit fullscreen mode

Alt Text

Top comments (0)