1. 程式人生 > 其它 >使用aspose-slides將ppt轉pdf

使用aspose-slides將ppt轉pdf

技術標籤:javappt

PPT轉PDF

下載jar包

連結:https://pan.baidu.com/s/1a-9zm9aaiEcemXD5jaLXRw 
提取碼:cu57 

新增到MVN倉庫中

mvn install:install-file -Dfile="jar包位置" -DgroupId="groupId" -DartifactId="artifactId" -Dversion="版本" -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true

匯入依賴

		<!--將ppt轉pdf 這是我自己的打包方式-->
        <dependency>
            <groupId>aspose</groupId>
            <artifactId>aspose-slides</artifactId>
            <version>19.3</version>
        </dependency>

程式碼

/**
     * ppt轉成pdf
     * @param sourcePath ppt的檔案路徑
     * @param savePath pdf儲存的路徑
     */
public static void pptToPdf(String sourcePath,String savePath){ FileOutputStream outputStream = null; //水印處理 final String license ="<License>\n" + " <Data>\n" + " <Products>\n" + " <Product>Aspose.Total for Java</Product> \n"
+ " </Products>\n" + " <EditionType>Enterprise</EditionType>\n" + " <SubscriptionExpiry>20991231</SubscriptionExpiry>\n" + " <LicenseExpiry>20991231</LicenseExpiry>\n" + " <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>\n" + " </Data>\n" + " <Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>\n" + "</License>"; try { //獲取水印 InputStream is = new ByteArrayInputStream(license.getBytes()); com.aspose.slides.License aposeLic = new com.aspose.slides.License(); aposeLic.setLicense(is); //讀取ppt檔案 FileInputStream fileInput = new FileInputStream(sourcePath); Presentation pres = new Presentation(fileInput); //指定輸出路徑 outputStream = new FileOutputStream(new File(savePath)); //輸出 pres.save(outputStream, SaveFormat.Pdf); outputStream.close(); }catch (Exception e){ e.printStackTrace(); } }

效果

在這裡插入圖片描述

僅學習使用,非商業用途