使用 Apache poi 将 ppt 转换为 png [英] Converting ppt to png using Apache poi

查看:37
本文介绍了使用 Apache poi 将 ppt 转换为 png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用 Apache Poi 框架将 ppt 的每张幻灯片转换为单独的 png.问题是一些幻灯片变形了.例如,有一张幻灯片,其背景为彩虹色.某些幻灯片上的图像根本不会出现在 .png 文件中

Hello I am trying to use the Apache Poi framework to convert each slide of a ppt to an individual png. The problem is that some slides are deformed. For instance there is a slide where the background has a rainbow color to it. And Images that are on some slides do not appear at all on the .png file

代码如下:

        FileInputStream is = new FileInputStream(args[0]);

        SlideShow ppt = new SlideShow(is);


        is.close();

        Dimension pgsize = ppt.getPageSize();

        Slide[] slide = ppt.getSlides();

        for (int i = 0; i < slide.length; i++) {

        BufferedImage img = new BufferedImage(pgsize.width, pgsize.height,
        BufferedImage.TYPE_INT_RGB);
        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("C:\\Users\\Farzad\\Desktop\\slide-" + (i+1) + ".png");
        javax.imageio.ImageIO.write(img, "png", out);
        out.close();
        }

推荐答案

为此,我们不必使用:

graphics.setPaint(Color.white);

改为使用:

graphics.setPaint(
    slideShow.getSlides()[0].getBackground().getFill().getForegroundColor()
);

这篇关于使用 Apache poi 将 ppt 转换为 png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆