gpt4 book ai didi

java - 有没有人有 Apache POI 将 PPTX 转换为 PNG 的示例

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:58:02 26 4
gpt4 key购买 nike

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

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

谢谢

最佳答案

同时它起作用了(...从 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();
}
}
}

关于java - 有没有人有 Apache POI 将 PPTX 转换为 PNG 的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3471472/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com