本文介绍了有没有人有 Apache POI 将 PPTX 转换为 PNG 的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

谢谢

推荐答案

在此期间它有效(...从 那里):

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

这篇关于有没有人有 Apache POI 将 PPTX 转换为 PNG 的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 05:46