springboot+openoffice实现 转换pdf

一、OpenOffice安装

二、       pom中依赖

<!-- jodconverter -->
        <dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-core</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-local</artifactId>
            <version>4.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-spring-boot-starter</artifactId>
            <version>4.3.0</version>
        </dependency>

三、 application配置文件中

jodconverter:
  local:
    enabled: true
   # max-tasks-per-process: 10
    port-numbers: 8100

 

四、java 

@Autowired
    private DocumentConverter converter; // 转换器

File file = new File("D:/test.xlsx");//需要转换的文件
            try {
                File newFile = new File("D:/pdf/");//转换之后文件生成的地址
                if (!newFile.exists()) {
                    newFile.mkdirs();
                }     
                //文件转化
                converter.convert(file).to(new File("D:/pdf/test.pdf")).execute();
                //使用response,将pdf文件以流的方式发送的前段
                ServletOutputStream outputStream = response.getOutputStream();
                InputStream in = new FileInputStream(new File("D:/pdf/test.pdf"));// 读取文件
                // copy文件
                IOUtils.copy(in, outputStream);
                in.close();
                outputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

参考传送门:https://blog.csdn.net/shipfei_csdn/article/details/105141487?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值