有Windows、Linux等版本,下载后安装
下载地址:
http://www.openoffice.org/download/index.html
2.jodconverter Maven依赖
(1).2.2.1版本
中央仓库里面有2.2.1和3.0-alfresco-patched-20141024版本,后者无法下载;
使用2.2.1版本可以正常转换txt、97-03的doc、xls、ppt为PPT,07及以后则会提示:unknown document format for file(未知文档格式)
<dependency>
<groupId>com.artofsolving</groupId>
<artifactId>jodconverter</artifactId>
<version>2.2.1</version>
</dependency>
(2).2.2.2版本
中央仓库没发现,去官网down了一个;之后需要将所依赖的jar包手动添加至到本地maven中(这个大家都会的就不多说了);
解压后进入lib目录,有个
DEPENDENCIES.txt
文件,这里面说明了所依赖的jar包,内容如下(大家都看得懂就不翻译了):
To use the library in your own Java app you need
-
* commons-io
-
* jodconverter
-
* juh
-
* jurt
-
* ridl
-
* slf4j-api
-
* slf4j-jdk14 or another slf4j implementation - see http://slf4j.org
-
* unoil
-
* xstream - only if you use XmlDocumentFormatRegistry
The command line interface additionally requires
-
* commons-cli
-
* jodconverter-cli
相关maven依赖如下,日志、io自行添加:
<!-- 需手动添加至仓库 -->
<dependency>
<groupId>com.artofsolving</groupId>
<artifactId>jodconverter</artifactId>
<version>2.2.2</version>
</dependency>
<!-- openoffice提供的jar,直接引用 -->
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>juh</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>jurt</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>ridl</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.openoffice</groupId>
<artifactId>unoil</artifactId>
<version>3.0.1</version>
</dependency>
下载地址:
https://sourceforge.net/projects/jodconverter/files/
文档转pdf
1.手动启动openoffice服务,在程序中调用该服务转换,本地openoffice安装在G:/Program Files (x86)/OpenOffice 4目录下
cd G:\Program Files (x86)\OpenOffice 4\program
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
2.代码
运行该程序时需先启动openoffice服务;测试了txt、doc、docx、xls、xlsx、ppt格式文件,均能转换成功
* 文档2pdf
* @param docFile 文件路径
* @param pdfFile pdf输出路径
* @return
public static boolean doc2pdf(File docFile, File pdfFile) {
boolean result = false;// 转换结果
if (docFile.exists()) {
if (!pdfFile.exists()) {
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
try {
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(docFile, pdfFile);
// 关闭连接
connection.disconnect();
result = true;
LOG.info("****pdf转换成功,PDF输出:" + pdfFile.getPath() + "****");
} catch (java.net.ConnectException e) {
LOG.error("openoffice服务未启动", e);
} catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) {
LOG.error("读取转换文件失败", e);
} catch (Exception e) {
LOG.error("转换失败", e);
} else {
result = true;
LOG.info("****已经转换为pdf,不需要再进行转化****");
} else {
LOG.info("****需要转换的文档不存在,无法转换****");
return result;
程序中启动openoffice服务,并转换文档为pdf;测试文件同方式一
* doc转pdf(程序启动openoffice)
* @param inputFile 输入文件
* @param outputFile 输出文件
* @return
public static boolean doc2pdf2(File inputFile, File outputFile) {
boolean result = false;
// OpenOffice的安装目录
String OpenOffice_HOME = "G:/Program Files (x86)/OpenOffice 4";
if (OpenOffice_HOME.charAt(OpenOffice_HOME.length() - 1) != '/') {
OpenOffice_HOME += "/";
Process process = null;
try {
// 启动OpenOffice的服务
String command = OpenOffice_HOME
+ "program/soffice.exe -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\"";
process = Runtime.getRuntime().exec(command);
// 连接 OpenOffice实例,运行在8100端口
OpenOfficeConnection connection = new SocketOpenOfficeConnection("127.0.0.1", 8100);
connection.connect();
// 转换
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
// 关闭连接
connection.disconnect();
// 销毁OpenOffice服务的进程
process.destroy();
LOG.info("****pdf转换成功,PDF输出:" + outputFile.getPath() + "****");
return true;
} catch (Exception e) {
LOG.error("pdf转换失败", e);
} finally {
if (process != null) {
process.destroy();
return result;
参考博客:
http://huangronaldo.iteye.com/blog/1628339
先来吐槽一下,近段时间做了很多其他乱七八糟的东西,做iOS开发,做iOS开发者账号申请,做后台,做产品分析,做产品原型,还做Wince开发。这些里面,Wince开发最后是放弃了,3年多没有玩vs2008
了,差不多都忘记了。
大四实习一年,毕业后又已经一年,从android到iOS,从iOS到做后台,从后台到做产品,每一层都有所学习(说到底还是团队内人力资源缺乏,导致要各种兼顾~~)。
1.
JODConverter
介绍:
JODConverter
automates conversions between office document formats using OpenOffice.org or LibreOffice.
Supported formats include OpenDocument,
PDF
, RTF, HTML, Wo
1.创建maven项目
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
&amp;lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
xmlns:xsi=&qu
JodConverter
: 功能强大的办公
文档
转换
工具
去发现同类优质开源项目:https://gitcode.com/
JodConverter
是一款开源的办公
文档
转换
工具,基于
Java
开发,可以将Microsoft Office和OpenOffice.org
文档
相互
转换
。这款强大的工具具有许多出色的特点,使其成为企业和个人在日常工作中进行
文档
转换
的理想选择。
一、项目概述
JodConvert...
JOD
转换
器
JODConverter
(用于
Java
OpenDocument Converter)
使用
LibreOffice或OpenOffice.org自动执行
文档
转换
。
:warning: 该存储库不再维护 :warning:
请改用或其他主动维护的fork。
我从2003年开始这个项目,并于2012年停止对其进行维护。我将代码移至GitHub,以期出现一个维护良好的fork。
该项目的上一个住所是 ,其中包括一些。
JODConverter
(
Java
OpenDocument Converter),可以
转换
不同Office格式的
文档
。它利用OpenOffice.org,可以自动化OpenOffice.org支持的所有
转换
。包括
转换
为
pdf
文件,部分支持
转换
到html文件。
JODConverter
下载地址:https://sourceforge.net/projects/
jodconverter
package com.syzton.teaching.util;
import com.artofsolving.
jodconverter
.DocumentConverter;
import com.artofsolving.
jodconverter
.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.
jodconverter
.openoffice.connection.SocketOpenOfficeCo
kikilada:
Spring - 事务(2)- 同一类中方法调用事务不起作用
kikilada:
Spring - 事务(2)- 同一类中方法调用事务不起作用
CSDN-Ada助手:
【Java并发】ReentrantReadWriteLock
CSDN-Ada助手: