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