简介

JODConverter,Java OpenDocument 转换器,可在不同办公格式之间转换文档。
它依赖于OpenOffice或者LibreOffice提供的服务来进行转换,它为当今可用的 OpenDocument格式 和 Microsoft Office 格式提供了可以说是最好的导入/导出。

JODConverter 自动执行 LibreOffice/OpenOffice 支持的所有转换,包括

  • Microsoft Office文档 到 OpenDocument文档, 反之亦然

    • Word 到 OpenDocument Text (odt); OpenDocument Text (odt) 到 Word
    • Excel 到 OpenDocument Spreadsheet (ods); OpenDocument Spreadsheet (ods) 到 Excel
    • PowerPoint 到 OpenDocument Presentation (odp); OpenDocument Presentation (odp) 到 PowerPoint
  • 任何格式 到 PDF
    • OpenDocument (Text, Spreadsheet, Presentation) 到 PDF
    • Word 到 PDF; Excel 到 PDF; PowerPoint 到 PDF
    • RTF 到 PDF; WordPerfect 到 PDF; …
  • 更多
    • OpenDocument Presentation (odp) 到 Flash; PowerPoint 到 Flash
    • RTF 到 OpenDocument; WordPerfect 到 OpenDocument
    • 任何格式 到 HTML (有限制)
    • 支持 OpenOffice.org 1.0 和旧的 StarOffice 格式

JODConverter 可以以多种不同方式使用

  • 作为 Java 库,嵌入到您自己的 Java 应用程序中
  • 作为命令行工具,可能从您自己的脚本中调用

用法

1: 先启动LibreOffice/OpenOffice

  • for Linux:

    #! /bin/bash#xhost +
    #export DISPLAY=:1.0 /path/to/openoffice/program/soffice.bin-headless -nofirststartwizard-accept="socket,host=localhost,port=8100;urp;StarOffice.Service"
    
  • for Mac OS X:

    /path/to/openoffice.app/Contents/MacOS/soffice.bin-headless -nofirststartwizard-accept="socket,host=localhost,port=8100;urp;StarOffice.Service"
    
  • for Windows:

    soffice.exe -headless-nofirststartwizard-accept="socket,host=localhost,port=8100;urp;StarOffice.Service"
    

2: 通过命令行来转换

例如把一个word文档转换成PDF文档:

REM 进入当前批处理文件所在的目录
cd /d %~dp0java -jar ./jodconverter-all-2.2.2.jar -v -h 127.0.0.1 -p 8100 ./test.doc ./test.pdf

3: 嵌入到Java程序中来转换

引入依赖:

  • Maven:
<dependency><groupId>com.github.wjw465150</groupId><artifactId>jodconverter-all</artifactId><version>2.2.2</version>
</dependency>
  • Gradle:
dependencies {implementation "com.github.wjw465150:jodconverter-all:2.2.2"
}

编写代码:

package wjw.test.JODConverter;import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry;
import com.artofsolving.jodconverter.DocumentConverter;
import com.artofsolving.jodconverter.DocumentFormat;
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;class Test {@BeforeAllstatic void setUpBeforeClass() throws Exception {}@AfterAllstatic void tearDownAfterClass() throws Exception {}@org.junit.jupiter.api.Testvoid test() {InputStream inFile = null;OutputStream outFile = null;OpenOfficeConnection con = null;try {inFile = Test.class.getClassLoader().getResourceAsStream("test.doc");outFile = new FileOutputStream("c:\\WJW_D\\test.pdf");// 创建Openoffice连接con = new SocketOpenOfficeConnection(8100);// 连接con.connect();DocumentFormat docDocumentFormat = (new DefaultDocumentFormatRegistry()).getFormatByFileExtension("doc");DocumentFormat pdfDocumentFormat = (new DefaultDocumentFormatRegistry()).getFormatByFileExtension("pdf");// 创建转换器DocumentConverter converter = new OpenOfficeDocumentConverter(con);// 转换文档converter.convert(inFile, docDocumentFormat, outFile, pdfDocumentFormat);System.out.println("转换成功!");} catch (Exception e) {System.out.println("转换失败!");e.printStackTrace();} finally {if (con != null) {// 关闭openoffice连接con.disconnect();}if (inFile != null) {try {inFile.close();} catch (IOException e) {e.printStackTrace();}}if (outFile != null) {try {outFile.close();} catch (IOException e) {e.printStackTrace();}}}}}

项目地址

https://github.com/wjw465150/jodconverter


<<<<<<<<<<<< [完] >>>>>>>>>>>

文档转换工具JODConverter简介相关推荐

  1. Word转PDF功能实现,文档转换工具通过PHP开发

    最近比较火的文档转换工具相信大家都听说过,但是怎么实现呢? 通过该接口可以将图片.word.excel.ppt等文档转换为pdf格式的文件 1.可以将Office(Word,Excel,PowerPo ...

  2. 软件分享:最好用的PDF文档转换工具和PDF套装企业版分享 | 附分享

    ---BEGIN--- PDF文档转换工具: 这是目前非常专业的一款pdf格式转换器,能够将pdf文件转换为word文件,同时也支持将pdf直接转换成其他格式的文件,如:excel.Html.powe ...

  3. 【如何将PDF转为word?PDF文档转换工具来啦!】

    PDF文档转换工具 最近,很多朋友都在找一个功能齐全,易用且免费的PDF文档转换工具,对此小编直接自己写了一个微信小程序,基本可以满足大家日常需求了.看大家的需要,后续可能还会退出pdf合并,加密等功 ...

  4. python文档生成工具 sphinx 简介

    目录 简介 sphinx-build用法 Makefile选项 调用sphinx-apidoc 原文出处 简介 Sphinx是一个工具,她能够轻易地创建智慧和优雅的文档,她是出自Georg Brand ...

  5. 免费在线文档转换工具,一招告诉你超简单.

    今天和大家分享一款在线转换工具,无论在什么操作系统, 只需要通过浏览器和互联网, 就能够轻松地完成多种格式转换操作.界面简洁美观,操作简单方便,功能非常强大,并且手机端也可以操作. 基本上可以满足对格 ...

  6. 【PC工具】PDF文档转换工具,PDF转word,PDF转excel等格式,全方位PDF转换器

    微信关注公众号 "DLGG创客DIY" 设为"星标",重磅干货,第一时间送达. 前言 上周分享了一个文库下载工具:[PC工具]更新免费xx文库文档下载器工具,下 ...

  7. 文档转换、在线预览的几种方式以及推荐

    互联网时代的繁荣期,在线教育犹如三国中的巴蜀之地,无论是各大巨头还是中小软件.都希望在此领域分的一口肥肉. 其中,关于文档转换.一直是开发在线教育软件让人头痛的事. 在这先说一下文档转换以及预览的几种 ...

  8. 怎么把一篇PDf文档转换成TXT格式

    之前从网上下载出来的文件都是PDF格式的,为了方便自己在手机上进行阅读需要转pdf能转为txt吗?答案当然是肯定的,pdf格式的电子书已经广泛应用于我们的工作和学习中,当我们希望把这类的pdf文件全部 ...

  9. openoffice jodconverter 文档转换pdf过坑记录

    文档转换性能测试 在财务系统中使用了两种PDF转换组件 一种是com.artofsolving,也是系统第一次引用的组件: <!-- https://mvnrepository.com/arti ...

最新文章

  1. linux网络驱动架构,Linux网络体系架构和网卡驱动设计
  2. 集合处理后,按原先输入的字符串顺序排序
  3. Mac 打开、编辑 .bash_profile 文件
  4. window.location.href如何多次请求_RabbitMQ如何保证幂等性?
  5. 在windows 2008/2012中配置RADIUS 客户端计算机上网WiFi 认证
  6. Java Sokect编程之HTTP请求
  7. 常用电源芯片特性大集合
  8. 面试准备每日五题:C++(五)——野指针、句柄指针、newdeletemallocfree、extern、类成员权限
  9. 蓝厂为什么着急推出vivo X23?只因vivo NEX叫好不叫座
  10. nginx url 重写_Nginx重写URL规则示例
  11. layer子父传值(1)
  12. 青岛科技大学古典音乐考试需要的资料
  13. 乱舞三国java_真.乱舞三国-江山美色
  14. 前端学习笔记之——使用 Window 对象
  15. TiDB+TiSpark部署--安装,扩缩容及升级操作
  16. lua游戏代码_在游戏中如何使用LUA脚本语言
  17. 打印魔方阵(C语言)
  18. 用python3的pyspider爬取国家统计局的行政区域(只到乡镇级,更新到2017年)
  19. 刚出社会的学弟:“毕业两年月薪才35K,真是没出息啊....”
  20. 小牛采购管理系统 bt

热门文章

  1. 用友U8年度帐结转解析
  2. 使用echarts配置中国地图
  3. QT5.9.0配置opencv
  4. DirectX游戏编程入门——第一部分(Windows和DirectX游戏编程引言) —— 初识DirectX
  5. java NameValuePair 实现 模拟 表单访问 服务 传输各类型数据
  6. 【软件测试】测试点总结,收取短信验证码的测试(详全),你的即用宝典......
  7. python爬虫下载小说_用PYTHON爬虫简单爬取网络小说
  8. 微信小程序校园学生选课教学论坛信息管理系统SSM-JAVA【数据库设计、论文、源码、开题报告】
  9. 毕业设计-基于微信小程序的移动端轻量 GIS 系统
  10. 免费在线一键领取饿了么手气最佳红包方法