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