Bug 57835 - XSLFSlide.importContent fails to create valid slide with Charts and Notes in slide
Summary: XSLFSlide.importContent fails to create valid slide with Charts and Notes in ...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSLF (show other bugs)
Version: 3.13-FINAL
Hardware: PC All
: P2 major with 14 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-20 17:58 UTC by Alexander
Modified: 2021-02-08 20:37 UTC (History)
5 users (show)



Attachments
Slide Source and Destination (couple Printshots) (397.30 KB, application/zip)
2015-04-20 17:58 UTC, Alexander
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander 2015-04-20 17:58:04 UTC
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>
Comment 1 Nicolas Cailloux 2015-12-24 10:41:44 UTC
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.
Comment 2 Nicolas Cailloux 2015-12-24 10:53:10 UTC
When digging in PPTX archive, the charts are not copied. I have as many charts in the new files than in the original one.
Comment 3 antonin pa 2017-05-02 09:15:07 UTC
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.
Comment 4 Alain Fagot Bearez 2017-09-13 17:31:18 UTC
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.
Comment 5 Alain Fagot Bearez 2021-02-08 20:37:42 UTC
While importing the charts has been available since POI 4.0.0, only with revision  r1886338 are the notes also imported.