【问题标题】:Converting ppt to png using Apache poi使用 Apache poi 将 ppt 转换为 png
【发布时间】:2011-03-07 01:43:10
【问题描述】:

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

代码如下:

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

【问题讨论】:

  • 改了BufferedImage.TYPE_INT_RGB会不会提高质量?
  • 您尝试使用什么版本的 POI? PPT渲染是一种随着时间的推移而改进的东西,所以如果你没有尝试过最新版本,那么值得升级
  • 会有人告诉我要包含哪个 jar 来运行上述代码。因为我没有获得 Dimension、Graphics2D 类..

标签: png apache-poi powerpoint hslf


【解决方案1】:

为此,我们不必使用:

graphics.setPaint(Color.white);

改为使用:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-27
    • 2023-03-14
    • 1970-01-01
    • 2013-07-23
    • 2012-03-21
    • 2012-11-19
    • 1970-01-01
    相关资源
    最近更新 更多