其他分享
首页 > 其他分享> > ppt和pdf转图片(Spire.Presentation)

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

    }
}

标签:java,import,image,Spire,ppt,pdf,Presentation
来源: https://www.cnblogs.com/zzsuje/p/12200484.html