- Code: Select all
tempLayout = (SlideLayoutPart)presMLPackage.getParts().getParts().get(pn);
won't create a part which doesn't already exist.
If you haven't added it already, you need to do so.
PresentationMLPackage.createPackage() contains:
- Code: Select all
SlideLayoutPart layoutPart = new SlideLayoutPart();
layoutPart.setJaxbElement( SlideLayoutPart.createSldLayout() );
You can adapt the second line of that...
You should also add it to a SlideMasterPart and vice versa
- Code: Select all
masterPart.addSlideLayoutIdListEntry(layoutPart);
layoutPart.addTargetPart(masterPart);
For ease of reference, here is the complete code of
Using java Syntax Highlighting
public static PresentationMLPackage createPackage
() throws InvalidFormatException
{
// Create a package
PresentationMLPackage pmlPack = new PresentationMLPackage
();
// Presentation part
MainPresentationPart pp
;
try {
pp
= new MainPresentationPart
();
pp.
setJaxbElement(MainPresentationPart.
createJaxbPresentationElement() );
pmlPack.
addTargetPart(pp
);
// Slide layout part
SlideLayoutPart layoutPart
= new SlideLayoutPart
();
layoutPart.
setJaxbElement( SlideLayoutPart.
createSldLayout() );
// Slide Master part
SlideMasterPart masterPart
= new SlideMasterPart
();
pp.
addSlideMasterIdListEntry(masterPart
);
masterPart.
setJaxbElement(masterPart.
createSldMaster() );
masterPart.
addSlideLayoutIdListEntry(layoutPart
);
layoutPart.
addTargetPart(masterPart
);
// Theme part
ThemePart themePart
= new ThemePart
(new PartName
("/ppt/theme/theme1.xml"));
java.
io.
InputStream is
= org.
docx4j.
utils.
ResourceUtils.
getResource(
"org/docx4j/openpackaging/parts/PresentationML/theme.xml");
themePart.
unmarshal(is
);
// .. add it in 2 places ..
masterPart.
addTargetPart(themePart
);
pp.
addTargetPart(themePart
);
} catch (Exception e
) {
e.
printStackTrace();
throw new InvalidFormatException
("Couldn't create package", e
);
}
// Return the new package
return pmlPack
;
}
Parsed in 0.016 seconds, using
GeSHi 1.0.8.4
see
http://207.46.16.248/en-us/library/gg278335.aspx re structure of pptx, or the images in
http://www.freshpatents.com/Structuring ... 277452.phpYou can also run your sample pptx through org.docx4j.samples.PartsList to get a feel for its structure.