JFreechart export to Powerpoint PPT

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
paintool
Posts: 1
Joined: Tue Jan 25, 2011 5:47 pm
antibot: No, of course not.

JFreechart export to Powerpoint PPT

Post by paintool » Tue Jan 25, 2011 5:49 pm

Is it possible to export a JFreechart chart to a Microsoft powerpoint slide?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: JFreechart export to Powerpoint PPT

Post by paradoxoff » Tue Jan 25, 2011 10:37 pm

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();
    }
}

HelenM
Posts: 1
Joined: Thu Apr 21, 2016 10:19 am
antibot: No, of course not.

Re: JFreechart export to Powerpoint PPT

Post by HelenM » Thu Apr 21, 2016 10:26 am

paradoxoff 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();
    }
}
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 Jfreechart :|

Howe
Posts: 1
Joined: Tue Aug 09, 2016 1:24 pm
antibot: No, of course not.

Re: JFreechart export to Powerpoint PPT

Post by Howe » Wed Aug 10, 2016 10:19 am

Hi,
I'm always used templates for PowerPoint from this site http://www.poweredtemplate.com/. Export will be working with these templates?

Locked