文档格式转换--JodConverter
功能介绍
JodConverter通过OpenOffice实现对各种类型文件的转换,支持的文档类型如下表:
源文件格式 | 目标文件格式 |
---|---|
Text Formats | |
OpenDocument Text (*.odt) | Portable Document Format (*.pdf) |
OpenOffice.org 1.0 Text (*.sxw) | OpenDocument Text (*.odt) |
Rich Text Format (*.rtf) | OpenOffice.org 1.0 Text (*.sxw) |
Microsoft Word (.doc、.docx) | Rich Text Format (*.rtf) |
WordPerfect (*.wpd) | Microsoft Word (*.doc) |
Plain Text (*.txt) | Plain Text (*.txt) |
HTML(*.html) | HTML2 (*.html) |
- | MediaWiki wikitext (*.wiki) |
Spreadsheet Formats | |
OpenDocument Spreadsheet (*.ods) | Portable Document Format (*.pdf) |
OpenOffice.org 1.0 Spreadsheet (*.sxc) | OpenDocument Spreadsheet (*.ods) |
Microsoft Excel (*.xls) | OpenOffice.org 1.0 Spreadsheet (*.sxc) |
Comma-Separated Values (*.csv) | Microsoft Excel (*.xls) |
Tab-Separated Values (*.tsv) | Comma-Separated Values (*.csv) |
- | Tab-Separated Values (*.tsv) |
- | HTML(*.html) |
Presentation Formats | |
OpenDocument Presentation (*.odp) | Portable Document Format (*.pdf) |
OpenOffice.org 1.0 Presentation (*.sxi) | Macromedia Flash (*.swf) |
Microsoft PowerPoint (*.ppt) | OpenDocument Presentation (*.odp) |
- | OpenOffice.org 1.0 Presentation (*.sxi) |
- | Microsoft PowerPoint (*.ppt) |
- | HTML (*.html) |
Drawing Formats | |
OpenDocument Drawing (*.odg) | Scalable Vector Graphics (*.svg) |
- | Macromedia Flash (*.swf) |
1 源文件格式中的HTML进行转换时可能不像浏览器展示那么准确,只能转换打印友好的网页
2 目标文件格式中的HTML可能包含多个文件,其他格式只会产生一个文件
官方网址:http://www.artofsolving.com/opensource/jodconverter/guide.html
应用案例
部署OpenOffice
使用OpenOffice3版本,安装OpenOffice完成后。在OpenOffice目录下使用以下命令启动OpenOffice,其中port指定了OpenOffice服务的端口,需与开发连接端口一致;nofirststartwizard指定不打开OpenOffice启动窗口,防止OpenOffice无法正常提供服务。
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
代码开发
采用JodConverter2.2.2版本开发
OpenOfficeService类用于和OpenOffice建立连接,考虑到JodConverter与OpenOffice建立连接较慢,OpenOfficeService类采用单例模式,提供了start和stop方法用于开启和关闭OpenOffice连接。
import java.io.IOException;import org.apache.log4j.Logger;import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;/*** ClassName: OpenOfficeService <br>* Description: OpenOffice服务,支持OpenOffice3.*版本,不支持OpenOffice4.*<br>* Create Date: 2017年1月11日 上午9:20:25 <br>* Modified By: <br>* Modified Date: <br>* Modified Content: <br>* Version: 1.0 <br>*/
public class OpenOfficeService {Logger log = Logger.getLogger(OpenOfficeService.class);/*** OpenOffice服务单例*/private volatile static OpenOfficeService instance = new OpenOfficeService();/*** 获取 OpenOffice服务单例<br>* @return OpenOffice服务单例*/public static OpenOfficeService getInstance() {return instance;}/*** 私有构造函数,通过静态方法getInstance获取实例对象*/private OpenOfficeService() {}/*** OpenOffice端口*/private int OPEN_OFFICE_PORT = 8100;/*** OpenOffice安装目录*/private String Open_Office_HOME = "C:/Program Files (x86)/OpenOffice.org 3/";/*** OpenOffice连接*/private OpenOfficeConnection connection;/*** 获取 OpenOffice连接<br>* @return connection OpenOffice连接* @throws IOException */public OpenOfficeConnection getConnection() throws IOException {if(!isRunning()) {start();}return connection;}/*** OpenOffice进程*/private Process openOfficeProcess;/*** 是否处于运行状态<br>* @return 运行状态*/public boolean isRunning() {if(connection == null) {return false;}return connection.isConnected();}/*** Description: 启动服务<br>* Create By: XX <br>* Create Date: 2017年1月11日 上午9:27:47* @return 是否成功* @throws IOException*/public void start() throws IOException {log.info("开始启动OpenOffice服务");/*String command = Open_Office_HOME + "program/soffice.exe -headless -accept=\"socket,host=127.0.0.1,port="+ OPEN_OFFICE_PORT + ";urp;\"";openOfficeProcess = Runtime.getRuntime().exec(command);*/log.info("开始连接到OpenOffice服务");connection = new SocketOpenOfficeConnection(OPEN_OFFICE_PORT);connection.connect();}/*** Description: 停止服务<br>* Create By: XX <br>* Create Date: 2017年1月11日 上午9:29:42*/public void stop() {log.info("关闭OpenOffice服务");if(connection != null && connection.isConnected()) {connection.disconnect();}if(openOfficeProcess != null) {openOfficeProcess.destroy();}}}
转换文件格式
OpenOfficeConnection connection;try {connection = OpenOfficeService.getInstance().getConnection();} catch (ConnectException e) {throw new Exception("无法连接到OpenOffice", e);}DocumentConverter converter = new OpenOfficeDocumentConverter(connection);// sourceFile源文件// destFile目标文件converter.convert(sourceFile, destFile);
文档格式转换--JodConverter相关推荐
- php 批量转换文档编码格式_据说是国内最好的文档格式转换网址~PDF,PPT,EXCEL,WORD互相转换...
作者 雷哥 | 编辑 小西瓜 各位读者朋友,大家好. 平时工作中,经常会遇到PDF转为Word,或者PPT转为Word,或者..... 遇到这种情况,大家有什么好的方法实现呢? 今天雷哥推荐给大家一个 ...
- 推荐一款全能的跨平台文档格式转换工具 Pandoc
公众号关注 「奇妙的 Linux 世界」 设为「星标」,每天带你玩转 Linux ! 如果您需要将文件从一种标记格式转换为另一种标记格式,那么?pandoc就是您的瑞士军刀. OpenSource: ...
- 如何利用 onlyoffice 实现文档格式转换
目录 前言 正文 启动 onlyoffice 服务 API 接口介绍 转换列表 请求示例 结尾 前言 日常生活和工作中,文档格式转换应该是很常见的需求.面对这样的需求,我们技术男有没有属于自己的好方法 ...
- Aconvert 文档格式转换-PDF转免费转其他文档网址-免费
现在市面上的文件转换软件都已经收费,且转换后文件真的不敢用! 今天分享一个免费的文档转换软件,可将PDF文档免费转换为:Word,Excel,PPT,HTML,TXT,DWG,JPG,PNG,GIF或 ...
- 文档格式转换工具对比
需求 免费.开源.中文字体不乱码.前后排版大致一样 工具对比 工具 缺点 xdocReport(poi) 排版会乱 docx4j 仅支持docx转换 document4j 仅适用在本地安装了offic ...
- 轻松实现各种文档格式转换,doc转pdf、doc转png图片、pdf转png图片,可以实现Windows、Linux、MacOS平台上部署(附源码和说明)
轻松实现各种文档格式转换,doc转pdf.doc转png图片.pdf转png图片,可以实现Windows.Linux.MacOS平台上部署,可以通过命令行.shell脚本.python等方式调用. 实 ...
- documents4j:Java文档格式转换开发库
为什么80%的码农都做不了架构师?>>> http://hao.jobbole.com/documents4j/ documents4j:Java文档格式转换开发库 docum ...
- [文档格式转换神器]pdf,jpg,xps转doc,xls,ppt等office格式
[文档格式转换神器]pdf,jpg,xps转doc,xls,ppt等office格式 Made By LuckyDog 今天公司财务遇到一个问题,同时也是给我出了一个难题(Because之前没弄过), ...
- word文档转为PDF以及多种文档格式转换
word文档转为PDF以及多种文档格式转换 项目地址:https://gitee.com/Jakewabc/word-of-pdf.git 相关案例: https://github.com/aspos ...
最新文章
- 设置VSCode代码编辑器右侧的Minimap代码缩略图滚动条切换显示、隐藏的快捷键Alt+M
- 极大似然估计_极大似然估计、极大后验估计和贝叶斯估计
- 剑指offer-包含min函数的栈
- java 中的 io 系统总结
- 自然语言生成(NLG)的好处是什么,它如何影响BI?
- Python批量导入Excel文件中的不重复数据到SQLite数据库
- 如何保证Session值不丢失
- 肯定存在无摩擦力的材料
- 基于java的高校实习生管理系统
- 要大容量有福了 Surface P4拆解可更换SSD!
- [架构之路-42]:目标系统 - 系统软件 - Linux下的网络通信-2-无线局域网WIFI原理、WIFI与3G/4G/以太网/蓝牙的协议转换
- Linux交叉编译FFmpeg
- matlab 模态,用matlab做模态分析
- 批量生成10位数手机号,用作账号注册
- vue划入划出事件_基于Vue.js中对鼠标划过事件的处理方式详解
- 实时网速怎么看快慢_如何知道网络的实时网速?4种方法轻松查询
- 推荐几款软件界面模型设计工具
- 弘辽科技:商家直通车操作
- Android的surface的三种工作方式
- 五大浏览器js 判断IE、Firefox、Safari、Chrome、Opera