Summary
The note information in the slide is only the specific content for the speaker to watch. When the speaker shows the slide, the note information can provide the speaker with explanation ideas and play an auxiliary role in explanation. This article will demonstrate how to operate the notes in the PPT slide through the Java program. The main points include:
- Add notes
- Modify note information
- Read notes
- Delete notes
Using tools
- Free flame.presentation for Java (free version)
Jar file acquisition and import:
Method 1: through the official website Download JAR File package. After downloading, extract the file and import the Spire.Presentation.jar file under the lib folder into the java program. Refer to the following import effect:
Method 2: available through maven Warehouse installation and import to maven project, please refer to Import method.
Java code example
[Example 1] Add Note Information
import com.spire.presentation.*; public class AddSpeakNotes { public static void main(String[] args) throws Exception{ //Load PowerPoint File Presentation ppt = new Presentation(); ppt.loadFromFile("sample.pptx"); //Get the first slide ISlide slide = ppt.getSlides().get(2); //Add notes slide to first slide NotesSlide notesSlide = slide.addNotesSlide(); //Add note title ParagraphEx paragraph = new ParagraphEx(); String string = "Remarks:"; paragraph.setText(string); notesSlide.getNotesTextFrame().getParagraphs().append(paragraph); //Add first note paragraph = new ParagraphEx(); paragraph.setText("Remark of the first item;"); notesSlide.getNotesTextFrame().getParagraphs().append(paragraph); notesSlide.getNotesTextFrame().getParagraphs().get(1).setBulletType(TextBulletType.NUMBERED); notesSlide.getNotesTextFrame().getParagraphs().get(1).setBulletStyle(NumberedBulletStyle.BULLET_ARABIC_PERIOD); //Add second note paragraph = new ParagraphEx(); paragraph.setText("The second remark;"); notesSlide.getNotesTextFrame().getParagraphs().append(paragraph); notesSlide.getNotesTextFrame().getParagraphs().get(2).setBulletType(TextBulletType.NUMBERED); notesSlide.getNotesTextFrame().getParagraphs().get(2).setBulletStyle(NumberedBulletStyle.BULLET_ARABIC_PERIOD); //Add third note paragraph = new ParagraphEx(); paragraph.setText("The third remark;"); notesSlide.getNotesTextFrame().getParagraphs().append(paragraph); notesSlide.getNotesTextFrame().getParagraphs().get(3).setBulletType(TextBulletType.NUMBERED); notesSlide.getNotesTextFrame().getParagraphs().get(3).setBulletStyle(NumberedBulletStyle.BULLET_ARABIC_PERIOD); //Save document ppt.saveToFile("AddSpeakerNotes.pptx", FileFormat.PPTX_2013); ppt.dispose(); } }
Note adding effect:
[example 2] modify note information
import com.spire.presentation.*; public class ModifySpeakerNotes { public static void main(String[] args) throws Exception{ //Load test document Presentation ppt = new Presentation(); ppt.loadFromFile("AddSpeakerNotes.pptx "); //Get the specified slide ISlide slide = ppt.getSlides().get(2); //Modify the specified note information slide.getNotesSlide().getNotesTextFrame().getParagraphs().get(1).setText("New modified notes"); slide.getNotesSlide().getNotesTextFrame().getParagraphs().get(2).setAlignment(TextAlignmentType.CENTER); slide.getNotesSlide().getNotesTextFrame().getParagraphs().get(2).setBulletStyle(NumberedBulletStyle.BULLET_ROMAN_UC_PAREN_RIGHT); //Save document ppt.saveToFile("modifySpeakerNotes.pptx",FileFormat.PPTX_2013); ppt.dispose(); } }
Note modification effect:
[example 3] read notes
import com.spire.presentation.*; import java.io.FileWriter; public class ExtractSpeakerNotes { public static void main(String[] args) throws Exception{ //Load test document Presentation ppt = new Presentation(); ppt.loadFromFile("AddSpeakerNotes.pptx"); //Get the specified slide ISlide slide = ppt.getSlides().get(2); //Get notes from slide StringBuilder builder = new StringBuilder(); String notes = slide.getNotesSlide().getNotesTextFrame().getText(); builder.append(notes); //Save to text document FileWriter writer = new FileWriter("ExtractSpeakerNotes.txt"); writer.write(builder.toString()); writer.flush(); writer.close(); } }
Reading result of remark information:
[example 4] delete note information
import com.spire.presentation.*; public class DeleteSpeakerNotes { public static void main(String[] args) throws Exception{ //Load test document Presentation ppt = new Presentation(); ppt.loadFromFile("test.pptx"); //Get the specified slide ISlide slide = ppt.getSlides().get(2); //Delete notes slide.getNotesSlide().getNotesTextFrame().getParagraphs().get(0).getTextRanges().clear();//Delete notes in the specified paragraph //slide.getNotesSlide().getNotesTextFrame().getParagraphs().clear();//Delete all comments //Save document ppt.saveToFile("deleteSpeakerNotes.pptx",FileFormat.PPTX_2013); ppt.dispose(); } }
Note information deletion effect:
(end of this paper)
Reprint please indicate the source!