将Java中的PPT(X)转换为PDF和图像
与PowerPoint相⽐,PDF(或图像)⽂件格式的优点是:
PDF /图像⽂件固定在页⾯布局中并且难以修改,因此更适合归档。由于PDF /图像⽂件与⼤多数设备兼容,因此交付更加⽅便。
For above reasons, you would probably convert your PowerPoint document into a PDF file or multiple image files. This article will show you how to accomplish this task by using .
下⾯是输⼊PowerPoint⽂档的屏幕截图。
PPT(X) to PDF
使⽤Spire.Presentation从PowerPoint到PDF的转换⾮常容易。 只需创建Presentation类的对象来保存要转换的PowerPoint⽂件,然后调⽤同⼀对象的saveToFile()⽅法即可将⽂档另存为PDF⽂件。
import com.spire.presentation.Presentation;
import com.spire.presentation.FileFormat;
public class PPTXtoPDF {
public static void main(String[] args) throws Exception {presentation什么意思
//create a Presentataion instance
Presentation presentation = new Presentation();
//load the sample PowerPoint file
presentation.loadFromFile("C:/Users/Administrator/Desktop/template.pptx");
//save to PDF file
presentation.saveToFile("ToPDF.pdf", FileFormat.PDF);
presentation.dispose();
}
}
PPT(X) to PNG
要将PowerPoint幻灯⽚导出为图像,⾸先需要使⽤saveAsImage()⽅法将每张幻灯⽚保存为BufferdImage,然后将图像数据写⼊.png ⽂件格式的图像⽂件中。
import com.spire.presentation.Presentation;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
public class ConvertPPTXtoPNG {
public static void main(String[] args) throws Exception {
//create a Presentation object
Presentation presentation = new Presentation();
//load an example PPTX file
presentation.loadFromFile("C:/Users/Administrator/Desktop/template.pptx");
//loop through the slides
for (int i = 0; i < Slides().getCount(); i++) {
//save each slide as a BufferedImage
BufferedImage image = Slides().get(i).saveAsImage();
//save BufferedImage as PNG file format
String fileName = String.format("ToImage-%1$s.png", i);
ImageIO.write(image, "PNG",new File(fileName));
}
presentation.dispose();
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论