Springboot ppt转pdf——aspose方式

Springboot ppt转pdf——aspose方式

1. 下载ppt转pdf所需要的包

[网盘地址](https://pan.baidu.com/s/1V-CZ0zXcJzKofxr6qC1g8A)
提取码:86lp

2. maven添加依赖

  1. 在项目根目录创建lib文件夹
  2. 将下载的aspose-slides.jar包,放在lib目录下在这里插入图片描述
  3. 在pom.xml 引入本地依赖包
    <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-slides</artifactId>
            <version>19.3</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/aspose.slides-19.3.jar</systemPath>
        </dependency>

3. 将license.xml文件放置在resources根目录下(去水印)

在这里插入图片描述

4. 创建java类,编写代码



import com.aspose.slides.License;
import com.aspose.slides.Presentation;

import com.aspose.slides.SaveFormat;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

import java.io.*;
import java.util.Date;

public class PPT2PdfAsposeUtil {
    public static boolean getLicensePPT() {
        boolean result = false;
        InputStream is = null;
        try {
            ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
            org.springframework.core.io.Resource[] resources = resolver.getResources("classpath:license.xml");
            is = resources[0].getInputStream();
            License aposeLic = new License();
            aposeLic.setLicense(is);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return result;
    }

    /**
     *
     * @param inPath ppt路径
     * @param outPath pdf路径
     * @return
     */
    public static boolean ppt2Pdf(String inPath,String outPath){
        // 验证License 去除水印
        if (!getLicensePPT()) {
            return false;
        }
        long start = new Date().getTime();
        try {
            FileInputStream fileInput = new FileInputStream(inPath);
            Presentation pres = new Presentation(fileInput);
            FileOutputStream out = new FileOutputStream(new File(outPath));
            pres.save(out, SaveFormat.Pdf);
            out.close();
        } catch (Exception e) {
             e.printStackTrace();
            return false;
        }
        long end = new Date().getTime();
        System.out.println("pdf转换成功,共耗时:" + ((end - start) / 1000.0) + "秒"); // 转化用时
        return true;
    }

    public static void main(String[] args) {
        ppt2Pdf("E:\\code\\test\\1.pptx","E:\\code\\test\\1.pdf");
    }
}

5. 测试

执行main方法

 public static void main(String[] args) {
        ppt2Pdf("E:\\code\\test\\1.pptx","E:\\code\\test\\1.pdf");
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小菜菜程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值