Bug 55164 - [PATCH] Support for adding slide notes
Summary: [PATCH] Support for adding slide notes
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: 3.10-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2013-06-30 16:03 UTC by Jan Tošovský
Modified: 2014-10-29 00:16 UTC (History)
0 users

Patch (3.82 KB, application/x-gzip)
2013-06-30 16:03 UTC, Jan Tošovský
Enhanced patch (5.76 KB, patch)
2013-08-25 18:58 UTC, Jan Tošovský
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Tošovský 2013-06-30 16:03:33 UTC
Created attachment 30506 [details]

This patch enables adding new slide notes into presentations without any notes (where no Notes Master slide and its relations are available). 
It uses a default Notes Master, the content of which is then imported into newly created notes slides. All new objects are linked accordingly.
Comment 1 Jan Tošovský 2013-06-30 16:32:49 UTC
A default Notes Master is provided as XML file in the resources folder. It is parsed and then copied completely (using a new constructor) into a new Notes Master object. Actually this template should be replaced with the 'EN' variant (I run on CZ locale).

For creating Note Slides I am reusing Notes Master content directly as there is no Layout analogy as in case of standard slides.

Important relation is between the Notes Master and the Theme object as some font properties are required during the processing. For the Notes Master I use the theme of the first slide.

But I had to use one nasty hack in the XSLFTextParagraph class. It supposes there are text styles defined in the Master, but these are not present in the Notes Master. I haven't found a way how to determine the kind of the Master so I placed another try into the exception fallback. It works, but...

As there is only one placeholder on the Notes Slide, we could consider placing the following verbose lookup code directly into the Note Slide class and call notesSlide.setNote("My Note") instead.

InputStream is = new FileInputStream("D:/test_multi.pptx");
XMLSlideShow slideShow = new XMLSlideShow(is);
for (XSLFSlide slide : slideShow.getSlides()) {
    XSLFNotes notesSlide = slideShow.createNotesSlide(slide);
    for (XSLFTextShape shape : notesSlide.getPlaceholders()) {
        if (shape.getTextType() == Placeholder.BODY) {
            shape.setText("My Note\nMy Note");
FileOutputStream out = new FileOutputStream("D:/test_multi_notes.pptx");

I would also prefer renaming XSLFNotes class into XSLFNotesSlide as it confused me many times in the beginning.
Comment 2 Jan Tošovský 2013-07-01 19:33:53 UTC
Comment on attachment 30506 [details]

My code tested with Office 2003 files fails for files created in version 2010. I suppose it is caused by that injected Notes Master which can contain version dependent content. I'll investigate it later.
Comment 3 Jan Tošovský 2013-08-25 18:58:41 UTC
Created attachment 30761 [details]
Enhanced patch

This patch can add new slide notes into a new presentation as well as into the existing one. This functionality is covered by three basic tests.

Problem in Office 2010 was caused by a lower tolerance when reusing the theme. Notes Master has to be linked to the different theme than the slides (but the theme itself can be the same, just with a different name).

So for the Notes Master, if not already specified, the theme of the first slide is reused (cloned). I don't know if my method is the best. There were no answers:

There are also issues in validation tool. They are caused by invalid 'Notes Slide' relations in presentation.xml.rels. They are created automatically. Maybe a new option for such cases will be needed. Discussed here:

In two places I work with the index of targetURis (e.g. 2 in /theme2.xml path). For this purpose I created a new helper method in POIXMLRelation class:
public Integer getFileNameIndex(POIXMLDocumentPart part)

Most of comments above is still valid.
Comment 4 Andreas Beeker 2014-10-29 00:16:06 UTC
Thank you for the patch - applied with small changes in r1635010

Regarding your two issues, I don't have recent MS-Office version available, but it works ok with Libre Office and the api is also ok - so if problems arise, there will be someone to announce/fix it ;)