Page 1 of 1

Problem converting pptx to pptx

PostPosted: Tue Aug 05, 2014 6:15 pm
by arturogalan
Hello, i'm working in a project that edit an existing Powerpoint with charts and embedded Excels and update the data to save a new document.
With charts i have no problem, following your sample code I update the chart and the spreadsheet at the same time and when I open the new document I can see the new data in slides.

My problem is with embedded Excels, I update the data but PowerPoint remains an .emf cache image of the initial spreadsheet data, so I have to open the powerpoint an double-click the Excel embedded spreadsheet in order to get the new data 'preview' image in the slide.

I have done an autoopen macro that refresh all the cached .emf images when you open the PowerPoint, but it changes the extension from pptx to 'pptm'.
In order to make the pptx4j library 'pptm' compatible, and following this post:
pptx-java-f14/ppsx-support-t754.html

I added the content type in org.docx4j.openpackaging.contenttype.ContentTypes:
PRESENTATION_MACROENABLED = "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"

And then make a one line addition to org.docx4j.openpackaging.contenttype.ContentTypeManager.createPackage()

else if (pkgContentType.equals(ContentTypes.PRESENTATIONML_MAIN)
|| pkgContentType.equals(ContentTypes.PRESENTATIONML_TEMPLATE)
|| pkgContentType.equals(ContentTypes.PRESENTATIONML_SLIDESHOW)
|| pkgContentType.equals(ContentTypes.PRESENTATION_MACROENABLED)) {
log.info("Detected PresentationMLPackage package ");
p = new PresentationMLPackage(this);
return p;

but i'm getting an error in Load3.addPartsFromRelationships(Base, RelationshipsPart, ContentTypeManager) line: 236:
java.lang.ClassCastException: org.docx4j.openpackaging.parts.DefaultXmlPart


¿ Please could you help me to make a patch to support pptm ? or ¿Any other idea for refreshing the img cache?

Thanks.

Re: Problem updating embedded Excel in PowerPoint

PostPosted: Tue Aug 05, 2014 7:49 pm
by jason
In [Content_Types].xml,

<Override PartName="/ppt/presentation.xml"
ContentType="application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml"/>

needs to change to:

<Override PartName="/ppt/presentation.xml"
ContentType="application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml"/>

So, to convert a pptx package to pptm you just need:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                        ContentTypeManager ctm = presentationMLPackage.getContentTypeManager();
                        ctm.removeContentType(new PartName("/ppt/presentation.xml") );
                        ctm.addOverrideContentType(new URI("/ppt/presentation.xml"),
                                  "application/vnd.ms-powerpoint.presentation.macroEnabled.main+xml");
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4


and then to save it with the appropriate file extension.

Adding the actual macro to the pptm pkg is another story...

Re: Problem converting pptx to pptx

PostPosted: Tue Aug 05, 2014 9:04 pm
by arturogalan
Hi, thanks for your quick response, but my idea is to read directly a pptm with the macro previously coded, not to convert a pptx into pptm.
Is in the sentence:

Code: Select all
PresentationMLPackage ppt = (PresentationMLPackage) OpcPackage.load(new java.io.File("myFile.pptm"));


where i get the error java.lang.ClassCastException: org.docx4j.openpackaging.parts.DefaultXmlPart...

Re: Problem converting pptx to pptx

PostPosted: Tue Aug 05, 2014 11:44 pm
by jason
Please see now https://github.com/plutext/docx4j/commi ... 234fa1f47b

This'll be included in 3.2.0, expected to be released late next week.

Re: Problem converting pptx to pptx

PostPosted: Tue Dec 02, 2014 9:55 pm
by Almirah
Hi,
Please reply the below information regarding the pptx4j. I'm new to pptx4j. :roll:
I will create one dynamic PPTX file by using pptx4j and need below clarification.