Page 1 of 1

Creating SmartArt using glox and Hierarchical data format

PostPosted: Tue Jun 02, 2015 8:47 pm
by michael.toft
Hey guys,

I am trying to generate a powerpoint with 1 page, containing a single SmartArt chart (hierarchycal)

I have downloaded the 3.2.1 binary of docx4j, plus dependencies, the sources, and its up and running locally.

I have been studying the code in CreatePptxWithSmartArt, and modified it to my particular setup.

However, when running the code I get an Exception trying to read the glox file.

I've attached the files and the hierarchycal data file im trying to parse.

The code is as follows (copied from CreatePptxWithSmartArt):

Code: Select all
public class MyTest {
   public static void main(String[] args) throws Exception {
      // Need the source doc as a DOM for later, and also
      // as XSLT input
      Document doc = XmlUtils.getNewDocumentBuilder().parse(
            new File("data-sample.xml"  ) );

      GloxPackage gloxPackage = (GloxPackage) OpcPackage.load(
            new File("test.glox")); [b]// FAILS HERE[/b]

      CTDiagramDefinition diagramLayoutObj = gloxPackage.getDiagramLayoutPart().getJaxbElement();

      Templates layoutTreeCreatorXslt =
            DiagramLayoutPart.generateLayoutTreeXSLT(
                  diagramLayoutObj);

      Templates layoutTree2DiagramDataXslt = XmlUtils.getTransformerTemplate(
            new StreamSource(
                  org.docx4j.utils.ResourceUtils.getResource(
                        "org/docx4j/openpackaging/parts/DrawingML/DiagramLayoutTree4AlgHier.xslt")));

      CreatePptxWithSmartArt creatorPptx = new CreatePptxWithSmartArt(diagramLayoutObj, layoutTreeCreatorXslt, layoutTree2DiagramDataXslt);

      PresentationMLPackage pkg = creatorPptx.createSmartArtPkg(SlideSizesWellKnown.A3, true, doc);

      SaveToZipFile saver = new SaveToZipFile(pkg);
      saver.save(new File(System.getProperty("user.dir")+ "/OUT.pptx"  ) );
      System.out.println("Done!");
   }
}


The exception

Code: Select all
Exception in thread "main" org.docx4j.openpackaging.exceptions.Docx4JException: No relationship of type officeDocument
   at org.docx4j.openpackaging.PackageRelsUtil.getNameOfMainPart(PackageRelsUtil.java:19)
   at org.docx4j.openpackaging.io3.Load3.get(Load3.java:145)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:454)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:371)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:262)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:242)
   at HierarchyBuilderTest.main(HierarchyBuilderTest.java:29)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)


Unzipping the glox file, i can see that the relations in fact does not contain the expected type "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"

It contains
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
-<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Target="/diagrams/layoutHeader1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramLayoutHeader"/><Relationship Id="rId2" Target="/diagrams/layout1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramLayout"/></Relationships>


I am new to all this, but have been reading Open XML Explained, and understand the basics (folder structure).

I am aware that there are other ways of creating the SmartArt in powerpoint, but I thought the glox approach was nice since I could use powerpoint to setup styles etc.

Any hints to how I get this running ?

And if there is a better way of doing this, i'd like to hear that aswell.

/Michael

Re: Creating SmartArt using glox and Hierarchical data forma

PostPosted: Wed Jun 03, 2015 8:11 pm
by jason
Hi Michael

Did you find the document "Creating SmartArt with docx4j"?

Its at https://github.com/plutext/docx4j/raw/m ... ocx4j.docx

That might shed some light on things.

Also, src/samples/glox4j

Please note the warning in there - you need to be a fairly brave soul to generate SmartArt. Although there are some people doing this commercially using the code in docx4j, it is an esoteric corner.

I ran your test.glox through ParseGlox and got the same error:

Exception in thread "main" org.docx4j.openpackaging.exceptions.Docx4JException: No relationship of type officeDocument
at org.docx4j.openpackaging.PackageRelsUtil.getNameOfMainPart(PackageRelsUtil.java:19)

So, where did the glox file come from? Does it work in Office?