JFreechart export to Powerpoint PPT
JFreechart export to Powerpoint PPT
Is it possible to export a JFreechart chart to a Microsoft powerpoint slide?
-
- Posts: 1634
- Joined: Sat Feb 17, 2007 1:51 pm
Re: JFreechart export to Powerpoint PPT
Yes.
Here a two methods that I quickly copied from one of my projects:
I am using apache POI for the powerpoint part and freehep VectorGraphics project to create the EMF file. "slideShow" is an instance of org.apache.poi.hslf.usermodel.SlideShow.
Here a two methods that I quickly copied from one of my projects:
I am using apache POI for the powerpoint part and freehep VectorGraphics project to create the EMF file. "slideShow" is an instance of org.apache.poi.hslf.usermodel.SlideShow.
Code: Select all
public void export(JFreeChart chart) throws Exception {
ByteArrayOutputStream emfout = new ByteArrayOutputStream();
EMFChartExporter ee = new EMFChartExporter(emfout);
ee.exportChart(chart, width, height);
int emfindex = slideShow.addPicture(emfout.toByteArray(), Picture.EMF);
Picture emf = new Picture(emfindex);
Slide slide = slideShow.createSlide();
emf.setAnchor(new java.awt.Rectangle(25, 100, (int)(width * scalingFactor), (int)(height * scalingFactor)));
slide.addShape(emf);
}
public class EMFChartExporter{
private OutputStream out;
public EMFChartExporter(OutputStream out) {
this.out = out;
}
public void exportChart(JFreeChart chart, int width, int height) throws IOException {
EMFGraphics2D g2d = new EMFGraphics2D(this.out, new Dimension(width, height));
g2d.setDeviceIndependent(true);//needs to be set, otherwise the export is lousy
g2d.startExport();
chart.draw((Graphics2D) g2d.create(), new Rectangle(width, height));
g2d.endExport();
g2d.closeStream();
}
}
Re: JFreechart export to Powerpoint PPT
Thank's, it really works!! I thought I can import it like I usually import animated templates from http://www.pptstar.com/powerpoint/animated/, but it didn't work with Jfreechartparadoxoff wrote:Yes.
Here a two methods that I quickly copied from one of my projects:
I am using apache POI for the powerpoint part and freehep VectorGraphics project to create the EMF file. "slideShow" is an instance of org.apache.poi.hslf.usermodel.SlideShow.Code: Select all
public void export(JFreeChart chart) throws Exception { ByteArrayOutputStream emfout = new ByteArrayOutputStream(); EMFChartExporter ee = new EMFChartExporter(emfout); ee.exportChart(chart, width, height); int emfindex = slideShow.addPicture(emfout.toByteArray(), Picture.EMF); Picture emf = new Picture(emfindex); Slide slide = slideShow.createSlide(); emf.setAnchor(new java.awt.Rectangle(25, 100, (int)(width * scalingFactor), (int)(height * scalingFactor))); slide.addShape(emf); } public class EMFChartExporter{ private OutputStream out; public EMFChartExporter(OutputStream out) { this.out = out; } public void exportChart(JFreeChart chart, int width, int height) throws IOException { EMFGraphics2D g2d = new EMFGraphics2D(this.out, new Dimension(width, height)); g2d.setDeviceIndependent(true);//needs to be set, otherwise the export is lousy g2d.startExport(); chart.draw((Graphics2D) g2d.create(), new Rectangle(width, height)); g2d.endExport(); g2d.closeStream(); } }
Re: JFreechart export to Powerpoint PPT
Hi,
I'm always used templates for PowerPoint from this site http://www.poweredtemplate.com/. Export will be working with these templates?
I'm always used templates for PowerPoint from this site http://www.poweredtemplate.com/. Export will be working with these templates?