When creating a PowerPoint document, you can add additional information to the speaker notes pane as a reference during presentation, the notes are visible on the presenter’s monitor but aren’t visible to the audiences. You can also remove the notes from the speaker notes pane if you don’t need it any more. In this article, I will illustrate how to add, read and remove speaker notes in a PowerPoint document in Java using Free Spire.Presentation for Java library.
Maven dependencies
To begin with, you need to specify the dependencies for Free Spire.Presentation for Java API in your maven project’s pom.xml file.
1. <repositories>
2.
3. <repository>
4.
5. <id>com.e-iceblue</id>
6.
7. <name>e-iceblue</name>
8.
9. <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
10.
11. </repository>
12.
13. </repositories>
14.
15. <dependencies>
16.
17. <dependency>
18.
19. <groupId>e-iceblue</groupId>
20.
21. <artifactId>spire.presentation.free</artifactId>
22.
23. <version>3.9.0</version>
24.
25. </dependency>
26.
27. </dependencies>
Add speaker notes
The NotesSlide class is used to work with speaker notes, by which you can add, read and remove speaker notes on a PowerPoint slide.
The following are the steps to add speaker notes to a slide:
- Create a Presentation instance and call loadFromFile method to load a PowerPoint document.
- Get the slide that you want to add notes to with Presentation.getSlides().get(int) method.
- Add notes slide to the slide with ISlide.addNotesSlide() method.
- Add text to the notes with NotesSlide.getNotesTextFrame().setText() method.
- Save the result document with Presentation.saveToFile(String, FileFormat) method.
- import com.spire.presentation.FileFormat;
- import com.spire.presentation.ISlide;
- import com.spire.presentation.NotesSlide;
- import com.spire.presentation.Presentation;
- public class AddSpeakerNotes {
- public static void main(String []args) throws Exception {
- //Create a Presentation instance
- Presentation ppt = new Presentation();
- //Load a PowerPoint document
- ppt.loadFromFile("sample.pptx");
- //Get the first slide
- ISlide slide = ppt.getSlides().get(0);
- //Add notes to the first slide
- NotesSlide notesSlide = slide.addNotesSlide();
- //Add text to the notes
- notesSlide.getNotesTextFrame().setText("Tips for making effective presentations.");
- //Save the result document
- ppt.saveToFile("AddSpleakerNotes.pptx", FileFormat.PPTX_2013);
- }
- }
Output:
Read speaker notes
It is quite straightforward to read the speaker notes in slide by using NotesSlide.getNotesTextFrame().getText() method.
- import com.spire.presentation.ISlide;
- import com.spire.presentation.Presentation;
- public class ReadSpeakerNotes {
- public static void main(String []args) throws Exception {
- //Create a Presentation instance
- Presentation ppt = new Presentation();
- //Load a PowerPoint document
- ppt.loadFromFile("AddSpleakerNotes.pptx");
- //Get the first slide
- ISlide slide = ppt.getSlides().get(0);
- //Read notes of the first slide
- String notes = slide.getNotesSlide().getNotesTextFrame().getText();
- System.out.println(notes);
- }
- }
Output:
Remove speaker notes
To remove speaker notes, you need to use NotesSlide.getNotesTextFrame().getParagraphs().clear() method.
- import com.spire.presentation.FileFormat;
- import com.spire.presentation.ISlide;
- import com.spire.presentation.NotesSlide;
- import com.spire.presentation.Presentation;
- public class RemoveSpeakerNotes {
- public static void main(String []args) throws Exception {
- //Create a Presentation instance
- Presentation ppt = new Presentation();
- //Load a PowerPoint document
- ppt.loadFromFile("AddSpleakerNotes.pptx");
- //Get the first slide
- ISlide slide = ppt.getSlides().get(0);
- //Remove notes from the first slide
- slide.getNotesSlide().getNotesTextFrame().getParagraphs().clear();
- //Save the result document
- ppt.saveToFile("RemoveSpleakerNotes.pptx", FileFormat.PPTX_2013);
- }
- }
Output:
Comments
Post a Comment