Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add notes to a Powerpoint slide using Apache POI

Is it possible to add notes to a powerpoint slide created programatically using Apache POI?

Here's what I have so far

Slide slide = ppt.createSlide();
org.apache.poi.hslf.record.Notes notesRecord = new ???; // <--- No Public constructor
org.apache.poi.hslf.model.Notes noteModel = new org.apache.poi.hslf.model.Notes(notesRecord ); // <--- Only one constructor which takes a org.apache.poi.hslf.record.Notes
// hopefully make some notes
// add the notes to the slide
slide.setNotes(noteModel);

As you can see, there doesn't seem to be a way to create the objects needed to add notes to the slide object.

Calling

Notes notesSheet = slide.getNotesSheet();

...returns null.

Is there another means to create the necessary notes object, perhaps using a factory class that I have not found?

Or, is there another way to add a note to a slide that doesn't involve working with the Note classes?

like image 795
Dónal Boyle Avatar asked Apr 26 '12 15:04

Dónal Boyle


1 Answers

The question ist quite old but I hope this answer will help someone. Using Apache POI 3.12 the following code should add some text as notes to a slide:

    // create a new empty slide show
    XMLSlideShow ppt = new XMLSlideShow();

    // add first slide
    XSLFSlide slide = ppt.createSlide();

    // get or create notes
    XSLFNotes note = ppt.getNotesSlide(slide);

    // insert text
    for (XSLFTextShape shape : note.getPlaceholders()) {
        if (shape.getTextType() == Placeholder.BODY) {
            shape.setText("String");
            break;
        }
    }

    // save
    [...]
like image 85
spilymp Avatar answered Nov 14 '22 22:11

spilymp