Page 1 of 1

Changing text in a pptx

PostPosted: Tue Apr 24, 2012 9:25 pm
by Raj
I need to create a PPTX with a few charts and venndiagrams.
For teh charts , I am plannign to use JFreeChart.
The Venndiagram cannot be drawn the same way. For docx I used a sample template with a Venndiagram drawing and changed the sample values to the actuals during runtime.
I was trying the same approach using pptx but cannot get it working.
For word I was using the method
Code: Select all
List texts = template.getMainDocumentPart().get
      .getJAXBNodesViaXPath(XPATH_TO_SELECT_TEXT_NODES, true);

to ge the text nodes and then was replacing it with actuals.
For PPTX I cannot find a similar method. Can you suggest how it can be done on similar lines?

Re: Changing text in a pptx

PostPosted: Wed Apr 25, 2012 3:24 am
by jason
I've committed http://www.docx4java.org/trac/docx4j/changeset/1804

If you are not building from source, this should be in http://www.docx4java.org/docx4j/docx4j- ... 120425.jar

Let me know how it goes.

Re: Changing text in a pptx

PostPosted: Wed Apr 25, 2012 9:39 pm
by Raj
How can I get the Slide Part from the MainPresentationTemplate?
In the docx version , I could search the entire docx file.
Do you have any documentation related to PPTX that can help me.
Code: Select all
PresentationMLPackage template =
         (PresentationMLPackage)PresentationMLPackage.load(new java.io.File("SampleVennDiagram.pptx"));      


Now I need to get the Slide Part from the template.
My aim here is to replace a text with an actual value. The text can be in any of the slides in the pptx.

Re: Changing text in a pptx

PostPosted: Wed Apr 25, 2012 10:09 pm
by Raj
I tried to get the SlidePart the following way:
Code: Select all
PresentationMLPackage template =
         (PresentationMLPackage)PresentationMLPackage.load(new java.io.File("S1.pptx"));      
      
      Parts parts = template.getParts();
      
      Map partsMap = parts.getParts();
      Set partsMapKeys = partsMap.keySet();
      for (Iterator it = partsMapKeys.iterator(); it.hasNext();) {
         Object o = it.next();
         System.out.println();
         System.out.println("The Key Name is "+o.toString());
         System.out.println("Value is "+partsMap.get(o));
         System.out.println();
         
         if("/ppt/slides/slide1.xml".equalsIgnoreCase(o.toString())){
            SlidePart sldPart = (SlidePart)partsMap.get(o);
            List texts = sldPart.getJAXBNodesViaXPath(XPATH_TO_SELECT_TEXT_NODES, true);
            System.out.println("Size of list "+texts.size());
            for (Object obj : texts) {
               Text text = (Text) ((JAXBElement) obj).getValue();
               String textValue = text.getValue();
               System.out.println("TEXTVALUE");
               System.out.println(" "+textValue);
               System.out.println("TEXTVALUE");
            }
         }
      }


HEre I was trying to get the text value that my PPTX contains. My Slide1.xml that i extracted using zip/unzip is attached.

The output I get from this is that the List if empty and the warnings:

The Key Name is /ppt/slides/slide1.xml
Value is org.docx4j.openpackaging.parts.PresentationML.SlidePart@1db0c7e

6235 [main] WARN org.docx4j.XmlUtils - no object association for xpath result!
6235 [main] WARN org.docx4j.XmlUtils - no object association for xpath result!
Size of list 0

Can you help me resolve this issue?

Re: Changing text in a pptx

PostPosted: Thu Apr 26, 2012 5:33 am
by jason
Looks like you have hit a dead end, due to a bug in JAXB or docx4j. This is not quite http://old.nabble.com/Binder---maintain ... 37052.html

Unless you feel like finding/fixing it, I suggest you try TraversalUtil. (There are a few JAXB related issues which affect docx4j; I'm planning to look into some of them, but this probably won't be the first)