Skip to main content

Add, Read and Remove Speaker Notes in PowerPoint in Java

 

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:

  1. Create a Presentation instance and call loadFromFile method to load a PowerPoint document.
  2. Get the slide that you want to add notes to with Presentation.getSlides().get(int) method.
  3. Add notes slide to the slide with ISlide.addNotesSlide() method.
  4. Add text to the notes with NotesSlide.getNotesTextFrame().setText() method.
  5. Save the result document with Presentation.saveToFile(String, FileFormat) method.

  1. import com.spire.presentation.FileFormat;  
  2. import com.spire.presentation.ISlide;  
  3. import com.spire.presentation.NotesSlide;  
  4. import com.spire.presentation.Presentation;  
  5.   
  6. public class AddSpeakerNotes {  
  7.     public static void main(String []args) throws Exception {  
  8.         //Create a Presentation instance  
  9.         Presentation ppt = new Presentation();  
  10.         //Load a PowerPoint document  
  11.         ppt.loadFromFile("sample.pptx");  
  12.   
  13.         //Get the first slide  
  14.         ISlide slide = ppt.getSlides().get(0);  
  15.         //Add notes to the first slide  
  16.         NotesSlide notesSlide = slide.addNotesSlide();  
  17.         //Add text to the notes  
  18.         notesSlide.getNotesTextFrame().setText("Tips for making effective presentations.");  
  19.   
  20.         //Save the result document  
  21.         ppt.saveToFile("AddSpleakerNotes.pptx", FileFormat.PPTX_2013);  
  22.     }  
  23. }  

Output:


Read speaker notes

It is quite straightforward to read the speaker notes in slide by using NotesSlide.getNotesTextFrame().getText() method.

  1. import com.spire.presentation.ISlide;  
  2. import com.spire.presentation.Presentation;  
  3.   
  4. public class ReadSpeakerNotes {  
  5.     public static void main(String []args) throws Exception {  
  6.         //Create a Presentation instance  
  7.         Presentation ppt = new Presentation();  
  8.         //Load a PowerPoint document  
  9.         ppt.loadFromFile("AddSpleakerNotes.pptx");  
  10.   
  11.         //Get the first slide  
  12.         ISlide slide = ppt.getSlides().get(0);  
  13.         //Read notes of the first slide  
  14.         String notes = slide.getNotesSlide().getNotesTextFrame().getText();  
  15.   
  16.         System.out.println(notes);  
  17.     }  
  18. }  

Output:


Remove speaker notes

To remove speaker notes, you need to use NotesSlide.getNotesTextFrame().getParagraphs().clear() method.

  1. import com.spire.presentation.FileFormat;  
  2. import com.spire.presentation.ISlide;  
  3. import com.spire.presentation.NotesSlide;  
  4. import com.spire.presentation.Presentation;  
  5.   
  6. public class RemoveSpeakerNotes {  
  7.     public static void main(String []args) throws Exception {  
  8.         //Create a Presentation instance  
  9.         Presentation ppt = new Presentation();  
  10.         //Load a PowerPoint document  
  11.         ppt.loadFromFile("AddSpleakerNotes.pptx");  
  12.   
  13.         //Get the first slide  
  14.         ISlide slide = ppt.getSlides().get(0);  
  15.         //Remove notes from the first slide  
  16.         slide.getNotesSlide().getNotesTextFrame().getParagraphs().clear();  
  17.   
  18.         //Save the result document  
  19.         ppt.saveToFile("RemoveSpleakerNotes.pptx", FileFormat.PPTX_2013);  
  20.     }  
  21. }  

Output:


 







Comments

Popular posts from this blog

3 Ways to Generate Word Documents from Templates in Java

A template is a document with pre-applied formatting like styles, tabs, line spacing and so on. You can quickly generate a batch of documents with the same structure based on the template. In this article, I am going to show you the different ways to generate Word documents from templates programmatically in Java using Free Spire.Doc for Java library. Prerequisite First of all, you need to add needed dependencies for including Free Spire.Doc for Java into your Java project. There are two ways to do that. If you use maven, you need to add the following code to your project’s pom.xml file. <repositories>               <repository>                   <id>com.e-iceblue</id>                   <name>e-iceblue</name> ...

Add Headers and Footers to Word document in Java

  In this blog, you will learn how to add headers and footers in a Word document in Java applications.   Contents Summary:   Add text to header Add image to header Add page numbers to footer The following example uses a free Java API - Free Spire.Doc for Java to achieve the above functionalities.   Add dependencies First of all, you need to add needed dependencies for including Free Spire.Doc for Java into your Java project. There are two ways to do that. If you use maven, you need to add the following code to your project’s pom.xml file.     <repositories>               <repository>                   <id>com.e-iceblue</id>                   <name>e-iceblue</name>    ...

Insert and Extract OLE objects in Word in Java

You can use OLE (Object Linking and Embedding) to include content from other programs, such as another Word document, an Excel or PowerPoint document to an existing Word document. This article demonstrates how to insert and extract embedded OLE objects in a Word document in Java by using Free Spire.Doc for Java API.   Add dependencies First of all, you need to add needed dependencies for including Free Spire.Doc for Java into your Java project. There are two ways to do that. If you use maven, you need to add the following code to your project’s pom.xml file.     <repositories>               <repository>                   <id>com.e-iceblue</id>                   <name>e-iceblue</name>     ...