use of org.pptx4j.pml.CTGraphicalObjectFrame in project Java-Tutorial by gpcodervn.
the class LinkToSlides method startPptx.
private static void startPptx() throws Exception {
// generate Ppt file
String outFileName = "output/LinkToSlides.pptx";
PresentationMLPackage presentationMLPackage = PresentationMLPackage.createPackage();
MainPresentationPart pp = (MainPresentationPart) presentationMLPackage.getParts().getParts().get(new PartName("/ppt/presentation.xml"));
SlideLayoutPart layoutPart = (SlideLayoutPart) presentationMLPackage.getParts().getParts().get(new PartName("/ppt/slideLayouts/slideLayout1.xml"));
// OK, now we can create a slide
SlidePart slidePart = null;
slidePart = presentationMLPackage.createSlidePart(pp, layoutPart, new PartName("/ppt/slides/slide1.xml"));
org.docx4j.relationships.ObjectFactory factory = new org.docx4j.relationships.ObjectFactory();
// first Link relation
org.docx4j.relationships.Relationship rel1 = factory.createRelationship();
rel1.setType(Namespaces.PRESENTATIONML_SLIDE);
rel1.setTarget("/ppt/slides/slide" + 5 + ".xml");
slidePart.getRelationshipsPart().addRelationship(rel1);
String linkedTable = table1.replaceFirst("replaceID", rel1.getId());
// second link relation
org.docx4j.relationships.Relationship rel2 = factory.createRelationship();
rel2.setType(Namespaces.PRESENTATIONML_SLIDE);
rel2.setTarget("/ppt/slides/slide" + 10 + ".xml");
slidePart.getRelationshipsPart().addRelationship(rel2);
linkedTable = linkedTable.replaceFirst("replaceID", rel2.getId());
CTGraphicalObjectFrame graphicFrame2 = (CTGraphicalObjectFrame) XmlUtils.unmarshalString(linkedTable, Context.jcPML, CTGraphicalObjectFrame.class);
slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(graphicFrame2);
for (int i = 2; i < 15; i++) {
slidePart = presentationMLPackage.createSlidePart(pp, layoutPart, new PartName("/ppt/slides/slide" + i + ".xml"));
Shape sample = ((Shape) XmlUtils.unmarshalString(getTextData(i), Context.jcPML));
slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(sample);
}
presentationMLPackage.save(new java.io.File(outFileName));
System.out.println("Done");
}
Aggregations