jodconverter word文档转PDF

1.创建maven项目
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.lht</groupId>
    <artifactId>jod</artifactId>
    <version>1.0</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.14.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-spring-boot-starter</artifactId>
            <version>4.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-local</artifactId>
            <version>4.2.0</version>
        </dependency>
    </dependencies>
</project>
2.编写spring boot 事件监听器
本文是为了做一个转码服务,和项目分开部署,如,在项目内部用可以注入DocumentConverter,在业务代码中调用
@Component
public class AppLisenter implements ApplicationListener<ApplicationReadyEvent> {


    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        ConfigurableApplicationContext context = event.getApplicationContext();
        DocumentConverter converter = context.getBean(DocumentConverter.class);
        try {
            converter.convert(new File("C:\\Users\\EDZ\\Desktop\\work\\(S)微商城项目功能清单.xlsx")).to(new File("C:\\Users\\EDZ\\Desktop\\work\\(S)微商城项目功能清单.pdf")).execute();
        } catch (OfficeException e) {
            e.printStackTrace();
        }
    }
}
3.编写启动类
@SpringBootApplication
public class TranscodingApplication {

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(TranscodingApplication.class);
        app.addListeners(new AppLisenter());
        app.run(args);
    }

}
4.编写配置文件
jodconverter:
  local:
    enabled: true #开启本地版
    office-home: D:\LibreOffice #libreoffice安装路径
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值