Page 1 of 1

Changing Template of a .pptx File

PostPosted: Wed Feb 13, 2013 7:50 pm
by nikhilesh.kumar
We have a requirement to change the template(.potx file) of a given .pptx file at runtime. Please provide pointers to the docx4J API's which can be used to achieve this.

Thanks

Re: Changing Template of a .pptx File

PostPosted: Wed Feb 13, 2013 10:21 pm
by jason
Please read http://openxmldeveloper.org/cfs-file.as ... lained.pdf which explains the structure of a pptx, and in particular where slide layout parts and slide master parts are attached.

You can also run your pptx through the PartsList sample, which will also show you this structure, and what Java objects docx4j/pptx4j uses to represent the parts.

You could then replace the contents of each part, with the contents of the corresponding part in the template, using .setJAXBEelement. That would probably be the simplest (assuming a 1:1 correspondence)

Alternatively, our MergePptx (not part of docx4j/pptx4j) could be used; you'd concatenate 0 slides from the template with the contents of the pptx whose appearance you wanted to change.

Re: Changing Template of a .pptx File

PostPosted: Fri Feb 15, 2013 12:48 am
by nikhilesh.kumar
Hi,
I've tried following code to change the Theme of pptx file, even though the Theme1.xml in the pptx package is modified accordingly(with extra namespaces), the Theme change is not reflected in the pptx file. Please provide pointers if, this is the right way to change the Theme in a presentation.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
/**********************Code**************************/
            String inputfilepath = "test1.pptx";
            PresentationMLPackage pptPackage = PresentationMLPackage.load(new java.io.File(inputfilepath));
            ThemePart themeSlidePart = (ThemePart) pptPackage.getParts().getParts().get(new PartName("/ppt/theme/theme1.xml"));
            Theme themeOfSlides = themeSlidePart.getJaxbElement();
            System.out.println("Theme of original PPT : " + XmlUtils.marshaltoString(themeOfSlides, true));
            //Part to apply Starts here

            String outputfilepath = "test3.pptx";
            PresentationMLPackage pptPackagetoApply = PresentationMLPackage.load(new java.io.File(outputfilepath));
            ThemePart themeSlidePartToApply = (ThemePart) pptPackagetoApply.getParts().getParts().get(new PartName("/ppt/theme/theme1.xml"));

            System.out.println("Theme B4 : " + XmlUtils.marshaltoString(themeSlidePartToApply.getJaxbElement(), true));
            themeSlidePartToApply.setJaxbElement(themeOfSlides);
            SaveToZipFile saver = new SaveToZipFile(pptPackagetoApply);
            saver.save(outputfilepath);
/*******************************************************************/
 
Parsed in 0.017 seconds, using GeSHi 1.0.8.4

-Nik

Re: Changing Template of a .pptx File

PostPosted: Fri Feb 15, 2013 1:04 pm
by jason
So you are saying the code changes the theme part, as expected? (The code certainly looks ok)

How were the theme parts different in the first place, and what visual effect were you expecting?

You may need to change your slide layout parts and/or slide master parts.

Re: Changing Template of a .pptx File

PostPosted: Fri Feb 15, 2013 5:17 pm
by nikhilesh.kumar
Yes, this code does change the theme1.xml of the test3.pptx(as desired) but the issue is, change in the theme is not reflected visually when presentation is opened(presentation still opens up with the older theme).
Slide layout part is about arrangement of content on various slides and hence different for each slide, while I'm just trying to change the Theme of the whole presentation.
Please provide any pointers on what could be the reason for this behavior.

Re: Changing Template of a .pptx File

PostPosted: Tue Feb 19, 2013 12:31 am
by nikhilesh.kumar
Is it enough to modify Theme1.xml to change the theme of a presentation, if not, What other files and properties/relations in the presentation package we need to change?

Re: Changing Template of a .pptx File

PostPosted: Sat Jun 15, 2013 12:30 am
by vijay.d99
Need help with changing theme for an existing PPTX. I read that you have faced the same issue few months back.

Have you got through the problem and if so, can you please provide some pointers.

Thanks
Vijay