Created attachment 32666 [details] Slide Source and Destination (couple Printshots) Have a presentation with a chart and some notes. Running the code below using the resources attached to this issue (src.pptx) generates the dst.pptx, such file is not being generated correctly, charts and notes are missing as shown in the attached pictures. The dst file can not be opened using powerpoint. POI: poi-ooxml-3.11-20141221 (Latest stable as of today) Java: jdk1.6.0_32 (32 bits) <TESTCODE> import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XSLFSlide; import org.apache.poi.xslf.usermodel.XSLFSlideLayout; import org.apache.poi.xslf.usermodel.XSLFSlideMaster; public class POITest { public static void main(String[] args) { try { String fnames[] = {"src.pptx"}; OutputStream fos = new FileOutputStream("dst.pptx"); XMLSlideShow ppt_out = new XMLSlideShow(); for (String file : fnames) { FileInputStream fis = new FileInputStream(file); XMLSlideShow src = new XMLSlideShow(fis); for(XSLFSlide srcSlide : src.getSlides()){ XSLFSlide newSlide = ppt_out.createSlide(); XSLFSlideLayout src_sl = srcSlide.getSlideLayout(); XSLFSlideMaster src_sm = srcSlide.getSlideMaster(); XSLFSlideLayout new_sl = newSlide.getSlideLayout(); XSLFSlideMaster new_sm = newSlide.getSlideMaster(); // copy source layout to the new layout new_sl.importContent(src_sl); // copy source master to the new master new_sm.importContent(src_sm); newSlide.importContent(srcSlide); } fis.close(); } ppt_out.write(fos); fos.close(); } catch (IOException e) { } } } </TESTCODE>
I also experience this bug. It seems POI succeeds in copying object, but fails in the type. Calling "getShapeName" results in the same name, but when trying to convert, here is what it says: org.apache.poi.POIXMLDocumentPart cannot be cast to org.apache.poi.xslf.usermodel.XSLFChart org.apache.poi.xslf.usermodel.XSLFPictureData cannot be cast to org.apache.poi.xslf.usermodel.XSLFChart Good news: the generated XML for the new chart object is the same as the original XML. The relation ID is the same (in my case, "rId2"). However, when checking in relations file for the slide, "rId2" is not bound to a chart anymore, but to an image. Also, some relations are simply missing. This seems to be a bug about relationships.
When digging in PPTX archive, the charts are not copied. I have as many charts in the new files than in the original one.
Encountering the exact same bug, that prevents me from using POI to generate power point presentations : I don't see how to *insert* graphs while building a presentation because of this bug.
A partial fix (only handling the charts) is available as pull request #68: https://github.com/apache/poi/pull/68 However the changes are not focused in solving only this issue, but in preparing for a shared code base for charts handling.
While importing the charts has been available since POI 4.0.0, only with revision r1886338 are the notes also imported.