You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by honyk <j....@email.cz> on 2013/05/10 19:43:55 UTC

[XSLF] Creating slide notes

Dear All,

while the reading current notes is quite straightforward, creating new ones
seems to be a challenge.

I've cloned XSLFNotes class (=MyNotes) with one extra constructor taking a
CTNotesSlide as a parameter. (XSLFNotes cannot be extented as it is final)

When testing this class using the following code it returns NPE:

public static void main(String[] args) {

        try {
            StringBuilder text = new StringBuilder();
            XMLSlideShow pptx = new XMLSlideShow(new
FileInputStream("D:/test.pptx"));
            for (XSLFSlide slide : pptx.getSlides()) {

                MyNotes notes = new
MyNotes(slide.getNotes().getXmlObject());
                slide.addRelation("test", notes);
            }

            FileOutputStream out = new FileOutputStream("D:/test_u.pptx");
            pptx.write(out);
            out.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

It reads notes which are already present and adds the second instance of
them to the same slide. I naively expected it could just double them in the
final file.

But this happens instead:

Exception in thread "main" java.lang.NullPointerException
	at
org.apache.poi.xslf.usermodel.XSLFSheet.commit(XSLFSheet.java:282)
	at
org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:313)
	at
org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:317)
	at
org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:317)
	at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:173)
	at net.gmc.util.slidenotes.App.main(App.java:42)
Java Result: 1

It was just the proof of concept. In my case I'd like to merge raw PPTX file
and an external XML file with notes grouped per slide. Notes in the form of
simple paragraphs would be sufficient for me. 

Has anybody any experience with this area? I am willing to investigate it,
but to be honest, this is the complete new thing for me so any introductory
guidance is highly appreciated.

Thanks, Jan




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


RE: [XSLF] Creating slide notes

Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 27 Jun 2013, honyk wrote:
> Thanks for your effort.
>
> There is a model for slide notes available:
> http://poi.apache.org/apidocs/org/apache/poi/xslf/usermodel/XSLFNotes.html

It'll almost certainly need some extending

> I can read slide notes from the existing presentation, so I know how the
> final XML fragment should look like:
>
> XMLSlideShow pptx = new XMLSlideShow(new FileInputStream("D:/test.pptx"));
> for (XSLFSlide slide : pptx.getSlides()) {
>    System.out.println(slide.getNotes().getXmlObject().xmlText());
> }
>
> How can inject this or slightly modified XML data back to the presentation?

You'll need to work with the opcpackage and packagepart objects to add the 
additional part, set up the relationships etc, then add suitable links / 
new xml to the parent slide to point to it

> Unfortunately XSLFNotes class has no constructor that would accept
> CTNotesSlide as a parameter. And it is final and cannot be extended.

Patch it then, and send us the patch :)

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


RE: [XSLF] Creating slide notes

Posted by honyk <j....@email.cz>.
On 2013-06-27 Nick Burch wrote:
> On Wed, 26 Jun 2013, honyk wrote:
> > I'd like to help with implementing the functionality for adding slide
> > notes to the presentation... please throw me a rope... thanks.
> 
> First step is to work out what XML is needed, and where. Try to get the
> very minimal amount that'll work. What XML do you need? Does it need to
> be
> in existing parts, or new parts? What relationships exist between the
> parts?
> 
> Creating several test files, unzipping them, and running diff against
> the
> xml (likely having run "xmllint -format" first to get pretty spacing)
> is
> the order of the day here. Oh, and check the list archives too for
> pointer
> from people who have already tried some of this
> 
> Then, with that done, try writing code to setup the new parts,
> injecting
> in preset xml, and modifying the existing xml parts with the raw CT
> beans.
> Then, create the initial new bits of xml with CT beans. Finally, wrap
> it
> all up in nice usermodel methods.
> 

Thanks for your effort. 

There is a model for slide notes available:
http://poi.apache.org/apidocs/org/apache/poi/xslf/usermodel/XSLFNotes.html

I can read slide notes from the existing presentation, so I know how the
final XML fragment should look like:

XMLSlideShow pptx = new XMLSlideShow(new FileInputStream("D:/test.pptx"));
for (XSLFSlide slide : pptx.getSlides()) {
    System.out.println(slide.getNotes().getXmlObject().xmlText());
}

This I've already written in my original post.

But I am repeating myself again :-)

How can inject this or slightly modified XML data back to the presentation?

Unfortunately XSLFNotes class has no constructor that would accept
CTNotesSlide as a parameter. And it is final and cannot be extended.

I suppose this new constructor could be as simple as this:

    XSLFNotes(CTNotesSlide notes) {
        super();
        _notes = notes;
    }

Now I have to:
1) somehow convert my raw XML data into CTNotesSlide object
2) somehow inject XSLFNotes object into the XSLFSlide

My use case is relatively simple. I have slides without any notes. I just
want to add several new notes into specific slides. So no modifications or
deleting, just adding new ones.

Jan


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


RE: [XSLF] Creating slide notes

Posted by Nick Burch <ap...@gagravarr.org>.
On Wed, 26 Jun 2013, honyk wrote:
> I'd like to help with implementing the functionality for adding slide 
> notes to the presentation... please throw me a rope... thanks.

First step is to work out what XML is needed, and where. Try to get the 
very minimal amount that'll work. What XML do you need? Does it need to be 
in existing parts, or new parts? What relationships exist between the 
parts?

Creating several test files, unzipping them, and running diff against the 
xml (likely having run "xmllint -format" first to get pretty spacing) is 
the order of the day here. Oh, and check the list archives too for pointer 
from people who have already tried some of this

Then, with that done, try writing code to setup the new parts, injecting 
in preset xml, and modifying the existing xml parts with the raw CT beans. 
Then, create the initial new bits of xml with CT beans. Finally, wrap it 
all up in nice usermodel methods.

Simple, hey? ;-)

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


RE: [XSLF] Creating slide notes

Posted by honyk <j....@email.cz>.
> I haven't found any method for injecting any arbitrary XML code to the
result yet

I'd like to help with implementing the functionality for adding slide notes
to the presentation... please throw me a rope... thanks.


> -----Original Message-----
> From: honyk [mailto:j.tosovsky@email.cz]
> Sent: Tuesday, May 21, 2013 7:55 PM
> To: 'POI Developers List'
> Subject: RE: [XSLF] Creating slide notes
> 
> Picked from another thread:
> > Technically speaking, adding support for notes in XLSF is not that
> > hard. The best way to understand how Presenatation ML does it is to
> > create two simple presentations: one without notes and the other with
> > a notes attached. Then unzip and diff the files.
> 
> Let's imagine I have XML code with notes. How can I inject it into the
> slide
> using XSLF correctly? The example below fails. I haven't found any
> other
> method for injecting any arbitrary XML code to the result yet.
> 
> Jan
> 
> 
> > -----Original Message-----
> > From: honyk [mailto:j.tosovsky@email.cz]
> > Sent: Friday, May 10, 2013 7:44 PM
> > To: dev@poi.apache.org
> > Subject: [XSLF] Creating slide notes
> >
> > Dear All,
> >
> > while the reading current notes is quite straightforward, creating
> new
> > ones
> > seems to be a challenge.
> >
> > I've cloned XSLFNotes class (=MyNotes) with one extra constructor
> > taking a
> > CTNotesSlide as a parameter. (XSLFNotes cannot be extented as it is
> > final)
> >
> > When testing this class using the following code it returns NPE:
> >
> > public static void main(String[] args) {
> >
> >         try {
> >             StringBuilder text = new StringBuilder();
> >             XMLSlideShow pptx = new XMLSlideShow(new
> > FileInputStream("D:/test.pptx"));
> >             for (XSLFSlide slide : pptx.getSlides()) {
> >
> >                 MyNotes notes = new
> > MyNotes(slide.getNotes().getXmlObject());
> >                 slide.addRelation("test", notes);
> >             }
> >
> >             FileOutputStream out = new
> > FileOutputStream("D:/test_u.pptx");
> >             pptx.write(out);
> >             out.close();
> >
> >         } catch (IOException e) {
> >             e.printStackTrace();
> >         }
> >     }
> >
> > It reads notes which are already present and adds the second instance
> > of
> > them to the same slide. I naively expected it could just double them
> in
> > the
> > final file.
> >
> > But this happens instead:
> >
> > Exception in thread "main" java.lang.NullPointerException
> > 	at
> > org.apache.poi.xslf.usermodel.XSLFSheet.commit(XSLFSheet.java:282)
> > 	at
> > org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:313)
> > 	at
> > org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:317)
> > 	at
> > org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:317)
> > 	at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:173)
> > 	at net.gmc.util.slidenotes.App.main(App.java:42)
> > Java Result: 1
> >
> > It was just the proof of concept. In my case I'd like to merge raw
> PPTX
> > file
> > and an external XML file with notes grouped per slide. Notes in the
> > form of
> > simple paragraphs would be sufficient for me.
> >
> > Has anybody any experience with this area? I am willing to
> investigate
> > it,
> > but to be honest, this is the complete new thing for me so any
> > introductory
> > guidance is highly appreciated.
> >
> > Thanks, Jan
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


RE: [XSLF] Creating slide notes

Posted by honyk <j....@email.cz>.
Picked from another thread:
> Technically speaking, adding support for notes in XLSF is not that
> hard. The best way to understand how Presenatation ML does it is to
> create two simple presentations: one without notes and the other with
> a notes attached. Then unzip and diff the files.

Let's imagine I have XML code with notes. How can I inject it into the slide
using XSLF correctly? The example below fails. I haven't found any other
method for injecting any arbitrary XML code to the result yet.

Jan


> -----Original Message-----
> From: honyk [mailto:j.tosovsky@email.cz]
> Sent: Friday, May 10, 2013 7:44 PM
> To: dev@poi.apache.org
> Subject: [XSLF] Creating slide notes
> 
> Dear All,
> 
> while the reading current notes is quite straightforward, creating new
> ones
> seems to be a challenge.
> 
> I've cloned XSLFNotes class (=MyNotes) with one extra constructor
> taking a
> CTNotesSlide as a parameter. (XSLFNotes cannot be extented as it is
> final)
> 
> When testing this class using the following code it returns NPE:
> 
> public static void main(String[] args) {
> 
>         try {
>             StringBuilder text = new StringBuilder();
>             XMLSlideShow pptx = new XMLSlideShow(new
> FileInputStream("D:/test.pptx"));
>             for (XSLFSlide slide : pptx.getSlides()) {
> 
>                 MyNotes notes = new
> MyNotes(slide.getNotes().getXmlObject());
>                 slide.addRelation("test", notes);
>             }
> 
>             FileOutputStream out = new
> FileOutputStream("D:/test_u.pptx");
>             pptx.write(out);
>             out.close();
> 
>         } catch (IOException e) {
>             e.printStackTrace();
>         }
>     }
> 
> It reads notes which are already present and adds the second instance
> of
> them to the same slide. I naively expected it could just double them in
> the
> final file.
> 
> But this happens instead:
> 
> Exception in thread "main" java.lang.NullPointerException
> 	at
> org.apache.poi.xslf.usermodel.XSLFSheet.commit(XSLFSheet.java:282)
> 	at
> org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:313)
> 	at
> org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:317)
> 	at
> org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:317)
> 	at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:173)
> 	at net.gmc.util.slidenotes.App.main(App.java:42)
> Java Result: 1
> 
> It was just the proof of concept. In my case I'd like to merge raw PPTX
> file
> and an external XML file with notes grouped per slide. Notes in the
> form of
> simple paragraphs would be sufficient for me.
> 
> Has anybody any experience with this area? I am willing to investigate
> it,
> but to be honest, this is the complete new thing for me so any
> introductory
> guidance is highly appreciated.
> 
> Thanks, Jan
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
> For additional commands, e-mail: dev-help@poi.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


RE: [XSLF] Creating slide notes

Posted by Jan Tosovsky <j....@email.cz>.
On 2013-11-22 zzzimon wrote:
> 
> Im trying to add notes dynamically to a power point presentation. I
> understand I have to compare the xml with notes and xml without notes.
> But then I have to somehow inject this into the slideshow but Im not 
> sure how.
> But the author of this thread found a solution. Has his or hers patch
> been added to the poi framework?

This functionality is patched, but not reviewed yet. Further progress can be
watched here:
https://issues.apache.org/bugzilla/show_bug.cgi?id=55164

It works fine for my files, but to be honest, some parts of code are
suboptimal.

In some cases instead of fundamental/dangerous changes in the codebase I've
chosen rather workarounds.

Jan


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [XSLF] Creating slide notes

Posted by zzzimon <si...@hotmail.com>.
Hi, im reviving this thread.

Im trying to add notes dynamically to a power point presentation. I
understand I have to compare the xml with notes and xml without notes. But
then I have to somehow inject this into the slideshow but Im not sure how.
But the author of this thread found a solution. Has his or hers patch been
added to the poi framework?

/Kind regards Simon



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/XSLF-Creating-slide-notes-tp5712676p5714329.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org