码迷,mamicode.com
首页 > 其他好文 > 详细

ppt和pdf转图片(Spire.Presentation)

时间:2020-01-16 12:52:40      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:page   red   tco   格式   dft   com   ice   jar   class   

在官网下载的

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

    }
}

ppt和pdf转图片(Spire.Presentation)

标签:page   red   tco   格式   dft   com   ice   jar   class   

原文地址:https://www.cnblogs.com/zzsuje/p/12200484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!