<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          使用Java 將PPT轉換為PDF、XPS等格式

          共 2327字,需瀏覽 5分鐘

           ·

          2020-08-30 09:16

          來源: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包導入方式:

          方式 1:通過官網下載Free Spire.Presentation for Java(https://www.e-iceblue.cn/Downloads/Free-Spire-Presentation-JAVA.html)類庫,解壓文檔后將lib文件夾下的Spire.Presentation.jar手動導入IDEA即可。具體導入步驟可參考下圖。


          方式 2:創(chuàng)建一個Maven應用程序,在pom.xml文件中配置Maven倉庫路徑及指定Spire.Presentation for Java的Maven依賴。

          <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>

          配置完成后,在IDEA中,您需點擊"Import Changes"即可導入JAR包;在Eclipse中,則需要點擊"Save"按鈕。

          PPT示例文檔:





          代碼示例


          示例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");
          //保存為PDF presentation.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 -

          瀏覽 52
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  一级A片免费观看 | 欧美乱三级 | 人妻精品一区二区 | 激情网五月天 | 伊人成人网大香蕉 |