Search code examples
docx4j

pptx4j: Support for Sections / Slidelist


Is there any api for PPTx Sections / SlideLists?

See http://msdn.microsoft.com/en-us/library/dd907440%28v=office.12%29.aspx

If there isn't, any suggestions how to start with this?

Thanks!


Solution

  • I've found a way to get the information i need.

    Comments are welcome.

    public static void main(String[] args) throws Exception
    {
        String inputfilepath="d:\\test.pptx";
        PresentationMLPackage presentationMLPackage=(PresentationMLPackage) PresentationMLPackage.load(new java.io.File(inputfilepath));
        CTExtensionList extLst = presentationMLPackage.getMainPresentationPart().getJaxbElement().getExtLst();
        for (CTExtension extension : extLst.getExt())
        {
            if ("{521415D9-36F7-43E2-AB2F-B90AF26B5E84}".equals(extension.getUri()))
            {
                Object any = extension.getAny();
                Node sectionListNode = null;
                if (any instanceof Node && "sectionLst".equals((sectionListNode = (Node) any).getLocalName()))
                {
                    for (int i = 0; i < sectionListNode.getChildNodes().getLength(); i++)
                    {
                        Node sectionNode = sectionListNode.getChildNodes().item(i);
                        String sectionName = ((Element)sectionNode).getAttribute("name").toString();
                        int sectionSlides = sectionNode.getFirstChild().getChildNodes().getLength();
                        System.out.println("Section:" + sectionName + " has childs:" + sectionSlides);
                    }
                }
            }
        }
    }