JodConverter 4.1.0 + OpenOffice 4.1.4 文档转换(Spring boot 1.5.8)
来源:互联网 发布:linux启动盘软碟通制作 编辑:程序博客网 时间:2024/06/05 03:17
注:本实例最终在 CentOS 7 上运行,Spring boot 最好是1.5.7 以上!
1、Maven 配置,最基本 JAR 包,当然还有可能需要其他包,根据提示或项目情况导入:
<dependency> <groupId>org.jodconverter</groupId> <artifactId>jodconverter-core</artifactId> <version>4.1.0</version></dependency><dependency> <groupId>org.jodconverter</groupId> <artifactId>jodconverter-local</artifactId> <version>4.1.0</version></dependency><dependency> <groupId>org.jodconverter</groupId> <artifactId>jodconverter-spring-boot-starter</artifactId> <version>4.1.0</version></dependency><dependency> <groupId>org.libreoffice</groupId> <artifactId>juh</artifactId> <version>5.4.2</version></dependency><dependency> <groupId>org.libreoffice</groupId> <artifactId>jurt</artifactId> <version>5.4.2</version></dependency><dependency> <groupId>org.libreoffice</groupId> <artifactId>ridl</artifactId> <version>5.4.2</version></dependency><dependency> <groupId>org.libreoffice</groupId> <artifactId>unoil</artifactId> <version>5.4.2</version></dependency><dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.2</version></dependency>
2、application.properties 配置如下:
################################################### JodConverter Configuration##################################################jodconverter.enabled=truejodconverter.officeHome=/opt/openoffice4jodconverter.portNumbers=8100, 8101, 8102, 8103, 8104, 8105, 8106, 8107, 8108, 8109jodconverter.maxTasksPerProcess=10
注意下分隔的格式,在 jodconverter-spring-boot-starter 包里可看到一些默认参数,如下:
@Configuration@ConditionalOnClass({DocumentConverter.class})@ConditionalOnProperty( prefix = "jodconverter", name = {"enabled"}, havingValue = "true", matchIfMissing = false)@EnableConfigurationProperties({JodConverterProperties.class})public class JodConverterAutoConfiguration { private final JodConverterProperties properties; public JodConverterAutoConfiguration(JodConverterProperties properties) { this.properties = properties; } private OfficeManager createOfficeManager() { Builder builder = LocalOfficeManager.builder(); if (!StringUtils.isBlank(this.properties.getPortNumbers())) { Set<Integer> iports = new HashSet(); String[] var3 = StringUtils.split(this.properties.getPortNumbers(), ", "); int var4 = var3.length; for(int var5 = 0; var5 < var4; ++var5) { String portNumber = var3[var5]; iports.add(NumberUtils.toInt(portNumber, 2002)); } builder.portNumbers(ArrayUtils.toPrimitive((Integer[])iports.toArray(new Integer[iports.size()]))); } builder.officeHome(this.properties.getOfficeHome()); builder.workingDir(this.properties.getWorkingDir()); builder.templateProfileDir(this.properties.getTemplateProfileDir()); builder.killExistingProcess(this.properties.isKillExistingProcess()); builder.processTimeout(this.properties.getProcessTimeout()); builder.processRetryInterval(this.properties.getProcessRetryInterval()); builder.taskExecutionTimeout(this.properties.getTaskExecutionTimeout()); builder.maxTasksPerProcess(this.properties.getMaxTasksPerProcess()); builder.taskQueueTimeout(this.properties.getTaskQueueTimeout()); return builder.build(); } @Bean( initMethod = "start", destroyMethod = "stop" ) @ConditionalOnMissingBean public OfficeManager officeManager() { return this.createOfficeManager(); } @Bean @ConditionalOnMissingBean @ConditionalOnBean({OfficeManager.class}) public DocumentConverter jodConverter(OfficeManager officeManager) { return LocalConverter.make(officeManager); }}
@ConfigurationProperties("jodconverter")public class JodConverterProperties { private boolean enabled; private String officeHome; private String portNumbers = "2002"; private String workingDir; private String templateProfileDir; private boolean killExistingProcess = true; private long processTimeout = 120000L; private long processRetryInterval = 250L; private long taskExecutionTimeout = 120000L; private int maxTasksPerProcess = 200; private long taskQueueTimeout = 30000L; public JodConverterProperties() { } public boolean isEnabled() { return this.enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; } public String getOfficeHome() { return this.officeHome; } public void setOfficeHome(String officeHome) { this.officeHome = officeHome; } public String getPortNumbers() { return this.portNumbers; } public void setPortNumbers(String portNumbers) { this.portNumbers = portNumbers; } public String getWorkingDir() { return this.workingDir; } public void setWorkingDir(String workingDir) { this.workingDir = workingDir; } public String getTemplateProfileDir() { return this.templateProfileDir; } public void setTemplateProfileDir(String templateProfileDir) { this.templateProfileDir = templateProfileDir; } public boolean isKillExistingProcess() { return this.killExistingProcess; } public void setKillExistingProcess(boolean killExistingProcess) { this.killExistingProcess = killExistingProcess; } public long getProcessTimeout() { return this.processTimeout; } public void setProcessTimeout(long processTimeout) { this.processTimeout = processTimeout; } public long getProcessRetryInterval() { return this.processRetryInterval; } public void setProcessRetryInterval(long procesRetryInterval) { this.processRetryInterval = procesRetryInterval; } public long getTaskExecutionTimeout() { return this.taskExecutionTimeout; } public void setTaskExecutionTimeout(long taskExecutionTimeout) { this.taskExecutionTimeout = taskExecutionTimeout; } public int getMaxTasksPerProcess() { return this.maxTasksPerProcess; } public void setMaxTasksPerProcess(int maxTasksPerProcess) { this.maxTasksPerProcess = maxTasksPerProcess; } public long getTaskQueueTimeout() { return this.taskQueueTimeout; } public void setTaskQueueTimeout(long taskQueueTimeout) { this.taskQueueTimeout = taskQueueTimeout; }}
3、最后在业务层引入 DocumentConverter,如下:
@Autowiredprivate DocumentConverter documentConverter;
documentConverter.convert(sourceFile).to(targetFile).execute();
说明:
jodconverter-core (转换核心包)
jodconverter-local(本地化部署,还有一个是 online 版,有需要自己去了解下)
jodconverter-spring-boot-starter(与 Spring boot 依赖配置)
参考 API 地址:http://javadoc.io/doc/org.jodconverter/jodconverter-core/4.1.0
阅读全文
0 0
- JodConverter 4.1.0 + OpenOffice 4.1.4 文档转换(Spring boot 1.5.8)
- JAVA结合OpenOffice转换office文档-jodconverter-core-3.0-beta-4
- openoffice jodconverter 文档转换pdf过坑记录
- 仿百度文库解决方案(四)——利用JODConverter调用OpenOffice.org服务转换文档为PDF
- 文档格式转换--JodConverter
- 利用 jodconverter 和openoffice 结合 把doc、ppt 等一系列文档转换成pdf
- JAVA OpenOffice+jodconverter转换WORD为PDF
- 仿百度文库方案[openoffice.org 3+swftools+flexpaper](三) 之 使用JODConverter将office文档转换为pdf
- 仿百度文库方案[openoffice.org 3+swftools+flexpaper](三) 之 使用JODConverter将office文档转换为pdf
- 仿百度文库方案[openoffice.org 3+swftools+flexpaper](三) 之 使用JODConverter将office文档转换为pdf
- 仿百度文库方案[openoffice.org 3+swftools+flexpaper] 使用JODConverter将office文档转换为pdf
- (二)使用JODConverter将office文档转换为pdf
- OpenOffice配合jodconverter多线程转换文件socket出现异常
- OpenOffice+JodConverter实现Office文件到PDF的转换
- 使用JODConverter转换文档为PDF
- 文档在线预览(二)-使用JODConverter转换文档为PDF
- 仿百度文库解决方案(三)- 利用JODConverter把文档转换成pdf格式
- debian openoffice文档转换服务
- JAVA中将一个List等分成n个list的工具方法
- COC软件设计原则
- javascript中的 变量,作用域和内存
- DisplayUtil
- 基数排序模板
- JodConverter 4.1.0 + OpenOffice 4.1.4 文档转换(Spring boot 1.5.8)
- java实现中文数字与阿拉伯数字互相转换
- 通过 xshell5 在系统linux 和 windows 中上传下载文件
- linux shell和配置文件的执行顺序
- java 包
- Maven install jar包到本地时报no pom错误
- layer的Icon样式以及一些常用的layer窗口使用
- 鱼找鱼阿虾找虾,KNN算法帮着乌龟找王八
- 线性基学习笔记