使用Java 將PPT轉換為PDF、XPS等格式
來源:SegmentFault 思否社區(qū)
作者:Tina_Tang
XPS(XML Paper Specification)是一個基于XML格式,以頁為單位的電子文檔格式。與PDF格式類似,其內容無法輕易變更,便于使用者進行保存、瀏覽及打印。本文將介紹如何用Java程序來將PPT文檔轉換為PDF及XPS格式,同時也將演示PPT與PPTX格式之間互轉的方式。
本文代碼的測試環(huán)境:
Intellij Idea2019.1 JDK 1.8.0 Spire.Presentation.jar
Jar包導入方式:

<repositories><repository><id>com.e-iceblueid><url>http://repo.e-iceblue.cn/repository/maven-public/url>repository>repositories><dependencies><dependency><groupId> e-iceblue groupId><artifactId>spire.presentation.freeartifactId><version>2.6.1version>dependency>dependencies>

代碼示例
示例1:PPT轉PDF
import com.spire.presentation.FileFormat;import com.spire.presentation.Presentation;public class ToPDF {public static void main(String[] args) throws Exception {//創(chuàng)建Presentation實例Presentation presentation = new Presentation();//加載PPT示例文檔presentation.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx");//保存為PDFpresentation.saveToFile("output/toPDF.pdf", FileFormat.PDF);presentation.dispose();}}

示例2:PPT轉XPS
import com.spire.presentation.*;public class ToXPS {public static void main(String[] args) throws Exception {//創(chuàng)建Presentation實例Presentation ppt = new Presentation();//加載PPT示例文檔ppt.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx");//保存為xps格式ppt.saveToFile("output/toXPS.xps", FileFormat.XPS);ppt.dispose();}}

示例3:PPT、PPTX格式互轉
import com.spire.presentation.FileFormat;import com.spire.presentation.Presentation;public class ToPPT {public static void main(String[] args) throws Exception {//創(chuàng)建Presentation對象Presentation ppt = new Presentation();//加載PPTX文檔 ppt.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pptx");//保存為PPT文檔ppt.saveToFile("output/ToPPT.ppt", FileFormat.PPT);//PPT轉PPTX//ppt.loadFromFile("C:/Users/Administrator/Desktop/example.ppt");//ppt.saveToFile("output/ToPPTX.pptx",FileFormat.PPTX_2013);ppt.dispose();}}點擊左下角閱讀原文,到?SegmentFault 思否社區(qū)?和文章作者展開更多互動和交流。 -?END -
評論
圖片
表情

