使用Java将ppt幻灯片提取为图像

使用Java将ppt幻灯片提取为图像,java,powerpoint,Java,Powerpoint,是否有一种方法可以使用Java以编程方式将幻灯片拆分为.png文件?我四处搜索了一下,给出的大多数答案要么是C语言的,要么提到的程序不是开源的你需要使用Java/COM桥接器,比如j-interop(http://www.j-interop.org/)以编程方式控制PowerPoint流程,然后可能将各个页面打印到文件中。您最好只编写一个VBA脚本。为了获得良好的质量,请在Apache POI HSLF库()中使用以下代码: FileInputStream is=newfileinputstre

是否有一种方法可以使用Java以编程方式将幻灯片拆分为.png文件?我四处搜索了一下,给出的大多数答案要么是C语言的,要么提到的程序不是开源的

你需要使用Java/COM桥接器,比如j-interop(http://www.j-interop.org/)以编程方式控制PowerPoint流程,然后可能将各个页面打印到文件中。您最好只编写一个VBA脚本。

为了获得良好的质量,请在Apache POI HSLF库()中使用以下代码:

FileInputStream is=newfileinputstream(“path_to_your.ppt”);
幻灯片ppt=新幻灯片(is);
is.close();
维度pgsize=ppt.getPageSize();
Slide[]Slide=ppt.getSlides();
对于(int i=0;i
在Apache POI库中使用以下代码

    FileInputStream is = new FileInputStream("D:\\PPT sample.ppt");
    XMLSlideShow ppt = new XMLSlideShow(is);
    is.close();

    Dimension pgsize = ppt.getPageSize();

    XSLFSlide[] slide = ppt.getSlides();
    for (int i = 0; i < slide.length; i++) {

        BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.SCALE_SMOOTH);
        Graphics2D graphics = img.createGraphics();
        //clear the drawing area
        graphics.setPaint(Color.white);
        graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));

        //render
        slide[i].draw(graphics);

        //save the output
        FileOutputStream out = new FileOutputStream("D:\\slide-"  + (i+1) + ".JPG");
        javax.imageio.ImageIO.write(img, "JPG", out);
        out.close();
FileInputStream is=newfileinputstream(“D:\\PPT sample.PPT”);
XMLSlideShow ppt=新的XMLSlideShow(is);
is.close();
维度pgsize=ppt.getPageSize();
XSLFSlide[]slide=ppt.getSlides();
对于(int i=0;i
Related:我自己没有这样做,所以我不会将此作为答案发布,但你应该看看这个:我删除了“unix”标记,因为它与这个问题无关。@David unix标记很可能是相关的,好像这需要在unix上工作,那么它就不能涉及包装Powerpoint本身的java库。@Peter:没有这个问题是针对unix的。IMO认为,这个问题适用于任何运行PowerPoint和Java的系统。
    FileInputStream is = new FileInputStream("D:\\PPT sample.ppt");
    XMLSlideShow ppt = new XMLSlideShow(is);
    is.close();

    Dimension pgsize = ppt.getPageSize();

    XSLFSlide[] slide = ppt.getSlides();
    for (int i = 0; i < slide.length; i++) {

        BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.SCALE_SMOOTH);
        Graphics2D graphics = img.createGraphics();
        //clear the drawing area
        graphics.setPaint(Color.white);
        graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));

        //render
        slide[i].draw(graphics);

        //save the output
        FileOutputStream out = new FileOutputStream("D:\\slide-"  + (i+1) + ".JPG");
        javax.imageio.ImageIO.write(img, "JPG", out);
        out.close();