ppt和pdf转图片(Spire.Presentation)
Posted zzsuje
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
}
}
以上是关于ppt和pdf转图片(Spire.Presentation)的主要内容,如果未能解决你的问题,请参考以下文章