ppt和pdf转图片(Spire.Presentation)

在官网下载的

Spire.Presentation.jar

https://www.e-iceblue.com/downloads/java/Spire.Presentation-FE_2.6.1.zip

 

package zyntest02;


import com.spire.pdf.*;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class TestPdfToImg {
    public static void main(String[] args) throws IOException {

PdfDocument pdf = new PdfDocument("f:\\123.pdf");
BufferedImage image;
for(int i = 0; i< pdf.getPages().getCount();i++){
    image = pdf.saveAsImage(i);
    File file = new File( String.format("f:\\ToImage-img-%d.png", i));
    ImageIO.write(image, "PNG", file);
}
pdf.close();
    }
}

 

package zyntest02;




import com.spire.presentation.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;

public class PPTtoPNG {
    public static void main(String[] args) throws Exception{
        //创建Presentation对象
        Presentation ppt = new Presentation();

        //加载示例文档
        ppt.loadFromFile("sample.pptx");

        //遍历幻灯片
        for (int i = 0; i < ppt.getSlides().getCount(); i++) {
            //将幻灯片保存为BufferedImage对象
            BufferedImage image = ppt.getSlides().get(i).saveAsImage();

            //将BufferedImage保存为PNG格式文件
            String fileName =  String.format("ToImage.png", i);
            ImageIO.write(image, "PNG",new File(fileName));
        }
        ppt.dispose();

    }
}

上一篇:如何克服做英文presentation的恐惧?


下一篇:Java 提取 PPT 中 SmartArt 图形的文本内容