有谁有 Apache POI 将 PPTX 转换为 PNG 的示例

发布于 2024-09-14 06:52:13 字数 104 浏览 5 评论 0原文

有谁知道将 PPTX powerpoint 演示文稿转换为某种形式的图像的好例子吗? PNG/GIF/等?

我可以做 PPT,但正在寻找 PPTX 转换示例

谢谢

Does anyone know of a good example of converting a PPTX powerpoint presentation to some form of image? PNG/GIF/etc?

I can do it for a PPT but looking for a PPTX conversion example

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

药祭#氼 2024-09-21 06:52:13

与此同时,它可以工作(...从那里复制它) :

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;

public class PptToPng {
    public static void main(String[] args) throws Exception {
        FileInputStream is = new FileInputStream("example.pptx");
        XMLSlideShow ppt = new XMLSlideShow(is);
        is.close();

        double zoom = 2; // magnify it by 2
        AffineTransform at = new AffineTransform();
        at.setToScale(zoom, zoom);

        Dimension pgsize = ppt.getPageSize();

        XSLFSlide[] slide = ppt.getSlides();
        for (int i = 0; i < slide.length; i++) {
            BufferedImage img = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = img.createGraphics();
            graphics.setTransform(at);

            graphics.setPaint(Color.white);
            graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
            slide[i].draw(graphics);
            FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png");
            javax.imageio.ImageIO.write(img, "png", out);
            out.close();
        }
    }
}

In the meantime it works (... copied it from there):

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;

public class PptToPng {
    public static void main(String[] args) throws Exception {
        FileInputStream is = new FileInputStream("example.pptx");
        XMLSlideShow ppt = new XMLSlideShow(is);
        is.close();

        double zoom = 2; // magnify it by 2
        AffineTransform at = new AffineTransform();
        at.setToScale(zoom, zoom);

        Dimension pgsize = ppt.getPageSize();

        XSLFSlide[] slide = ppt.getSlides();
        for (int i = 0; i < slide.length; i++) {
            BufferedImage img = new BufferedImage((int)Math.ceil(pgsize.width*zoom), (int)Math.ceil(pgsize.height*zoom), BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = img.createGraphics();
            graphics.setTransform(at);

            graphics.setPaint(Color.white);
            graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));
            slide[i].draw(graphics);
            FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png");
            javax.imageio.ImageIO.write(img, "png", out);
            out.close();
        }
    }
}
却一份温柔 2024-09-21 06:52:13

为了回答我自己的问题,我订阅了开发邮件列表并提出了这个问题。

答案是apache poi目前不支持这个功能

Answering my own question, I subscribed to the development mailing list and asked this question.

The answer is that this functionailty is currently not supported by apache poi

还给你自由 2024-09-21 06:52:13

现在有一个示例类 PPTX2PNG 与 POI 捆绑在一起,对于我扔给它的 PPTX 平台来说,它似乎可以产生不错的结果:

http://svn.apache.org/repos/asf/poi/trunk /src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java

There's an example class PPTX2PNG now bundled with POI that seems to work with decent results for the PPTX decks I've thrown at it:

http://svn.apache.org/repos/asf/poi/trunk/src/ooxml/java/org/apache/poi/xslf/util/PPTX2PNG.java

半透明的墙 2024-09-21 06:52:13

pptx4j 可以帮助您在 HTML 中创建 SVG(尽管仍然需要做一些工作来支持所有形状);然后您可以使用其中一种工具从自动浏览器窗口创建图像。

pptx4j can help you to create SVG in HTML (though there is still work to do to support all shapes); and then you could use one of the tools which create a image from an automated browser window.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文