---
title: "openoffice 转换各种文件"
author: "qqpedily"
date: "2011-12-21T11:56:12Z"
tags: ["openoffice 转换各种文件"]
categories: ["开源软件"]
slug: "openoffice"
draft: false
lastmod: "2011-12-21T11:56:12Z"
id: 1319348
url: "https://qqpedily.iteye.com/blog/1319348"
---

Java代码 1.2010-07-30 11:01 2. 3.此页由Linux Wiki用户Chenxing于2008年3月11日 (星期二) 10:45的最后更改。 4.出自Linux Wiki 5.在Linux中常常涉及到多种文档格式，如doc、txt、html、rtf等等。为了方便文件传递，就可能需要在各种格式之间进行转换。 OpenOffice.Org可以方便的打开多各文档格式并按需进行转换，但要一次处理大量文件或要编写脚本进行转换时，仅用OpenOffice就难以胜任了。 6. 7.unoconv利用OpenOffice.Org的UNO接口实现了命令行文档格式转换功能，支持所有OpenOffice支持的文件格式，为文档的批量转换提供了可能。 8. 9.目录 10.\[隐藏] 11.•1 下载及安装 12.•2 使用方法 13.◦2.1 单个文件转换 14.◦2.2 批量转换 15.•3 其它功能简介 16.◦3.1 支持的文件格式 17.◦3.2 服务器/客户端模式 18.•4 附：支持的输出文件格式 19.•5 相关资料 20. 21.下载及安装 22.目前Debian的源已经有unoconv，如果你使用的发行版还没有unoconv，可以到它的主页下载： http://dag.wieers.com/home-made/unoconv/ 。 23. 24.注意： 25.该软件依赖于OpenOffice.Org。 26.使用方法 27.单个文件转换 28.举一个例子：要转换一个doc文件为PDF格式，只需在命令中执行： 29. 30.$ unoconv -f pdf myDoc.doc 31.即会生成一个名为myDoc.pdf的pdf文件。 32. 33.批量转换 34.批量转换需要结合find命令或脚本使用，使用时需注意最好使用C/S模式以加快速度： 35. 36.unoconv --listener & 37.unoconv -f pdf some-document.odt 38.unoconv -f doc other-document.odt 39.unoconv -f jpg some-image.png 40.unoconv -f xsl some-spreadsheet.csv 41.其它功能简介 42.支持的文件格式 43.可以执行unoconv --show查看截止到2008年3月11日，unoconv支持以下几种导出格式（见本文末尾）\[1] 44. 45.服务器/客户端模式 46.此模式使文档的集中处理成为可能。 47. 48.附：支持的输出文件格式 49.bib - BibTeX \[.bib] 50.doc - Microsoft Word 97/2000/XP \[.doc] 51.doc6 - Microsoft Word 6.0 \[.doc] 52.doc95 - Microsoft Word 95 \[.doc] 53.docbook - DocBook \[.xml] 54.html - HTML Document (OpenOffice.org Writer) \[.html] 55.odt - Open Document Text \[.odt] 56.ott - Open Document Text \[.ott] 57.ooxml - Microsoft Office Open XML \[.xml] 58.pdb - AportisDoc (Palm) \[.pdb] 59.pdf - Portable Document Format \[.pdf] 60.psw - Pocket Word \[.psw] 61.rtf - Rich Text Format \[.rtf] 62.latex - LaTeX 2e \[.ltx] 63.sdw - StarWriter 5.0 \[.sdw] 64.sdw4 - StarWriter 4.0 \[.sdw] 65.sdw3 - StarWriter 3.0 \[.sdw] 66.stw - Open Office.org 1.0 Text Document Template \[.stw] 67.sxw - Open Office.org 1.0 Text Document \[.sxw] 68.text - Text Encoded \[.txt] 69.txt - Plain Text \[.txt] 70.vor - StarWriter 5.0 Template \[.vor] 71.vor4 - StarWriter 4.0 Template \[.vor] 72.vor3 - StarWriter 3.0 Template \[.vor] 73.xhtml - XHTML Document \[.html] 74.图形格式: 75. 76.bmp - Windows Bitmap \[.bmp] 77.emf - Enhanced Metafile \[.emf] 78.eps - Encapsulated PostScript \[.eps] 79.gif - Graphics Interchange Format \[.gif] 80.html - HTML Document (OpenOffice.org Draw) \[.html] 81.jpg - Joint Photographic Experts Group \[.jpg] 82.met - OS/2 Metafile \[.met] 83.odd - OpenDocument Drawing \[.odd] 84.otg - OpenDocument Drawing Template \[.otg] 85.pbm - Portable Bitmap \[.pbm] 86.pct - Mac Pict \[.pct] 87.pdf - Portable Document Format \[.pdf] 88.pgm - Portable Graymap \[.pgm] 89.png - Portable Network Graphic \[.png] 90.ppm - Portable Pixelmap \[.ppm] 91.ras - Sun Raster Image \[.ras] 92.std - OpenOffice.org 1.0 Drawing Template \[.std] 93.svg - Scalable Vector Graphics \[.svg] 94.svm - StarView Metafile \[.svm] 95.swf - Macromedia Flash (SWF) \[.swf] 96.sxd - OpenOffice.org 1.0 Drawing \[.sxd] 97.sxd3 - StarDraw 3.0 \[.sxd] 98.sxd5 - StarDraw 5.0 \[.sxd] 99.tiff - Tagged Image File Format \[.tiff] 100.vor - StarDraw 5.0 Template \[.vor] 101.vor3 - StarDraw 3.0 Template \[.vor] 102.wmf - Windows Metafile \[.wmf] 103.xhtml - XHTML \[.xhtml] 104.xpm - X PixMap \[.xpm] 105.演示文稿: 106. 107.bmp - Windows Bitmap \[.bmp] 108.emf - Enhanced Metafile \[.emf] 109.eps - Encapsulated PostScript \[.eps] 110.gif - Graphics Interchange Format \[.gif] 111.html - HTML Document (OpenOffice.org Impress) \[.html] 112.jpg - Joint Photographic Experts Group \[.jpg] 113.met - OS/2 Metafile \[.met] 114.odd - OpenDocument Drawing (Impress) \[.odd] 115.odg - OpenOffice.org 1.0 Drawing (OpenOffice.org Impress) \[.odg] 116.odp - OpenDocument Presentation \[.odp] 117.otp - OpenDocument Presentation Template \[.otp] 118.pbm - Portable Bitmap \[.pbm] 119.pct - Mac Pict \[.pct] 120.pdf - Portable Document Format \[.pdf] 121.pgm - Portable Graymap \[.pgm] 122.png - Portable Network Graphic \[.png] 123.pot - Microsoft PowerPoint 97/2000/XP Template \[.pot] 124.ppm - Portable Pixelmap \[.ppm] 125.ppt - Microsoft PowerPoint 97/2000/XP \[.ppt] 126.pwp - PlaceWare \[.pwp] 127.ras - Sun Raster Image \[.ras] 128.sda - StarDraw 5.0 (OpenOffice.org Impress) \[.sda] 129.sdd - StarImpress 5.0 \[.sdd] 130.sdd3 - StarDraw 3.0 (OpenOffice.org Impress) \[.sdd] 131.sdd4 - StarImpress 4.0 \[.sdd] 132.sti - OpenOffice.org 1.0 Presentation Template \[.sti] 133.stp - OpenDocument Presentation Template \[.stp] 134.svg - Scalable Vector Graphics \[.svg] 135.svm - StarView Metafile \[.svm] 136.swf - Macromedia Flash (SWF) \[.swf] 137.sxi - OpenOffice.org 1.0 Presentation \[.sxi] 138.tiff - Tagged Image File Format \[.tiff] 139.vor - StarImpress 5.0 Template \[.vor] 140.vor3 - StarDraw 3.0 Template (OpenOffice.org Impress) \[.vor] 141.vor4 - StarImpress 4.0 Template \[.vor] 142.vor5 - StarDraw 5.0 Template (OpenOffice.org Impress) \[.vor] 143.wmf - Windows Metafile \[.wmf] 144.xhtml - XHTML \[.xml] 145.xpm - X PixMap \[.xpm] 146.电子表格: 147. 148.csv - Text CSV \[.csv] 149.dbf - dBase \[.dbf] 150.dif - Data Interchange Format \[.dif] 151.html - HTML Document (OpenOffice.org Calc) \[.html] 152.ods - Open Document Spreadsheet \[.ods] 153.ooxml - Microsoft Excel 2003 XML \[.xml] 154.pdf - Portable Document Format \[.pdf] 155.pts - OpenDocument Spreadsheet Template \[.pts] 156.pxl - Pocket Excel \[.pxl] 157.sdc - StarCalc 5.0 \[.sdc] 158.sdc4 - StarCalc 4.0 \[.sdc] 159.sdc3 - StarCalc 3.0 \[.sdc] 160.slk - SYLK \[.slk] 161.stc - OpenOffice.org 1.0 Spreadsheet Template \[.stc] 162.sxc - OpenOffice.org 1.0 Spreadsheet \[.sxc] 163.vor3 - StarCalc 3.0 Template \[.vor] 164.vor4 - StarCalc 4.0 Template \[.vor] 165.vor - StarCalc 5.0 Template \[.vor] 166.xhtml - XHTML \[.xhtml] 167.xls - Microsoft Excel 97/2000/XP \[.xls] 168.xls5 - Microsoft Excel 5.0 \[.xls] 169.xls95 - Microsoft Excel 95 \[.xls] 170.xlt - Microsoft Excel 97/2000/XP Template \[.xlt] 171.xlt5 - Microsoft Excel 5.0 Template \[.xlt] 172.xlt95 - Microsoft Excel 95 Template \[.xlt] 173.相关资料 174.1.↑ http://dag.wieers.com/home-made/unoconv/ 175. 176.转自：http://www.linux-wiki.cn/index.php/%E6%96%87%E6%A1%A3%E6%A0%BC%E5%BC%8F%E6%89%B9%E9%87%8F%E8%BD%AC%E6%8D%A2(doc,txt,pdf%E7%AD%89)#.E5.8D.95.E4.B8.AA.E6.96.87.E4.BB.B6.E8.BD.AC.E6.8D.A2 177. 178. 179.本文来自CSDN博客，转载请标明出处：http://blog.csdn.net/antony1029/archive/2010/04/30/5547767.aspx 2010-07-30 11:01 此页由Linux Wiki用户Chenxing于2008年3月11日 (星期二) 10:45的最后更改。 出自Linux Wiki 在Linux中常常涉及到多种文档格式，如doc、txt、html、rtf等等。为了方便文件传递，就可能需要在各种格式之间进行转换。 OpenOffice.Org可以方便的打开多各文档格式并按需进行转换，但要一次处理大量文件或要编写脚本进行转换时，仅用OpenOffice就难以胜任了。 unoconv利用OpenOffice.Org的UNO接口实现了命令行文档格式转换功能，支持所有OpenOffice支持的文件格式，为文档的批量转换提供了可能。 目录 \[隐藏] •1 下载及安装 •2 使用方法 ◦2.1 单个文件转换 ◦2.2 批量转换 •3 其它功能简介 ◦3.1 支持的文件格式 ◦3.2 服务器/客户端模式 •4 附：支持的输出文件格式 •5 相关资料 下载及安装 目前Debian的源已经有unoconv，如果你使用的发行版还没有unoconv，可以到它的主页下载： http://dag.wieers.com/home-made/unoconv/ 。 注意： 该软件依赖于OpenOffice.Org。 使用方法 单个文件转换 举一个例子：要转换一个doc文件为PDF格式，只需在命令中执行： $ unoconv -f pdf myDoc.doc 即会生成一个名为myDoc.pdf的pdf文件。 批量转换 批量转换需要结合find命令或脚本使用，使用时需注意最好使用C/S模式以加快速度： unoconv --listener & unoconv -f pdf some-document.odt unoconv -f doc other-document.odt unoconv -f jpg some-image.png unoconv -f xsl some-spreadsheet.csv 其它功能简介 支持的文件格式 可以执行unoconv --show查看截止到2008年3月11日，unoconv支持以下几种导出格式（见本文末尾）\[1] 服务器/客户端模式 此模式使文档的集中处理成为可能。 附：支持的输出文件格式 bib - BibTeX \[.bib] doc - Microsoft Word 97/2000/XP \[.doc] doc6 - Microsoft Word 6.0 \[.doc] doc95 - Microsoft Word 95 \[.doc] docbook - DocBook \[.xml] html - HTML Document (OpenOffice.org Writer) \[.html] odt - Open Document Text \[.odt] ott - Open Document Text \[.ott] ooxml - Microsoft Office Open XML \[.xml] pdb - AportisDoc (Palm) \[.pdb] pdf - Portable Document Format \[.pdf] psw - Pocket Word \[.psw] rtf - Rich Text Format \[.rtf] latex - LaTeX 2e \[.ltx] sdw - StarWriter 5.0 \[.sdw] sdw4 - StarWriter 4.0 \[.sdw] sdw3 - StarWriter 3.0 \[.sdw] stw - Open Office.org 1.0 Text Document Template \[.stw] sxw - Open Office.org 1.0 Text Document \[.sxw] text - Text Encoded \[.txt] txt - Plain Text \[.txt] vor - StarWriter 5.0 Template \[.vor] vor4 - StarWriter 4.0 Template \[.vor] vor3 - StarWriter 3.0 Template \[.vor] xhtml - XHTML Document \[.html] 图形格式: bmp - Windows Bitmap \[.bmp] emf - Enhanced Metafile \[.emf] eps - Encapsulated PostScript \[.eps] gif - Graphics Interchange Format \[.gif] html - HTML Document (OpenOffice.org Draw) \[.html] jpg - Joint Photographic Experts Group \[.jpg] met - OS/2 Metafile \[.met] odd - OpenDocument Drawing \[.odd] otg - OpenDocument Drawing Template \[.otg] pbm - Portable Bitmap \[.pbm] pct - Mac Pict \[.pct] pdf - Portable Document Format \[.pdf] pgm - Portable Graymap \[.pgm] png - Portable Network Graphic \[.png] ppm - Portable Pixelmap \[.ppm] ras - Sun Raster Image \[.ras] std - OpenOffice.org 1.0 Drawing Template \[.std] svg - Scalable Vector Graphics \[.svg] svm - StarView Metafile \[.svm] swf - Macromedia Flash (SWF) \[.swf] sxd - OpenOffice.org 1.0 Drawing \[.sxd] sxd3 - StarDraw 3.0 \[.sxd] sxd5 - StarDraw 5.0 \[.sxd] tiff - Tagged Image File Format \[.tiff] vor - StarDraw 5.0 Template \[.vor] vor3 - StarDraw 3.0 Template \[.vor] wmf - Windows Metafile \[.wmf] xhtml - XHTML \[.xhtml] xpm - X PixMap \[.xpm] 演示文稿: bmp - Windows Bitmap \[.bmp] emf - Enhanced Metafile \[.emf] eps - Encapsulated PostScript \[.eps] gif - Graphics Interchange Format \[.gif] html - HTML Document (OpenOffice.org Impress) \[.html] jpg - Joint Photographic Experts Group \[.jpg] met - OS/2 Metafile \[.met] odd - OpenDocument Drawing (Impress) \[.odd] odg - OpenOffice.org 1.0 Drawing (OpenOffice.org Impress) \[.odg] odp - OpenDocument Presentation \[.odp] otp - OpenDocument Presentation Template \[.otp] pbm - Portable Bitmap \[.pbm] pct - Mac Pict \[.pct] pdf - Portable Document Format \[.pdf] pgm - Portable Graymap \[.pgm] png - Portable Network Graphic \[.png] pot - Microsoft PowerPoint 97/2000/XP Template \[.pot] ppm - Portable Pixelmap \[.ppm] ppt - Microsoft PowerPoint 97/2000/XP \[.ppt] pwp - PlaceWare \[.pwp] ras - Sun Raster Image \[.ras] sda - StarDraw 5.0 (OpenOffice.org Impress) \[.sda] sdd - StarImpress 5.0 \[.sdd] sdd3 - StarDraw 3.0 (OpenOffice.org Impress) \[.sdd] sdd4 - StarImpress 4.0 \[.sdd] sti - OpenOffice.org 1.0 Presentation Template \[.sti] stp - OpenDocument Presentation Template \[.stp] svg - Scalable Vector Graphics \[.svg] svm - StarView Metafile \[.svm] swf - Macromedia Flash (SWF) \[.swf] sxi - OpenOffice.org 1.0 Presentation \[.sxi] tiff - Tagged Image File Format \[.tiff] vor - StarImpress 5.0 Template \[.vor] vor3 - StarDraw 3.0 Template (OpenOffice.org Impress) \[.vor] vor4 - StarImpress 4.0 Template \[.vor] vor5 - StarDraw 5.0 Template (OpenOffice.org Impress) \[.vor] wmf - Windows Metafile \[.wmf] xhtml - XHTML \[.xml] xpm - X PixMap \[.xpm] 电子表格: csv - Text CSV \[.csv] dbf - dBase \[.dbf] dif - Data Interchange Format \[.dif] html - HTML Document (OpenOffice.org Calc) \[.html] ods - Open Document Spreadsheet \[.ods] ooxml - Microsoft Excel 2003 XML \[.xml] pdf - Portable Document Format \[.pdf] pts - OpenDocument Spreadsheet Template \[.pts] pxl - Pocket Excel \[.pxl] sdc - StarCalc 5.0 \[.sdc] sdc4 - StarCalc 4.0 \[.sdc] sdc3 - StarCalc 3.0 \[.sdc] slk - SYLK \[.slk] stc - OpenOffice.org 1.0 Spreadsheet Template \[.stc] sxc - OpenOffice.org 1.0 Spreadsheet \[.sxc] vor3 - StarCalc 3.0 Template \[.vor] vor4 - StarCalc 4.0 Template \[.vor] vor - StarCalc 5.0 Template \[.vor] xhtml - XHTML \[.xhtml] xls - Microsoft Excel 97/2000/XP \[.xls] xls5 - Microsoft Excel 5.0 \[.xls] xls95 - Microsoft Excel 95 \[.xls] xlt - Microsoft Excel 97/2000/XP Template \[.xlt] xlt5 - Microsoft Excel 5.0 Template \[.xlt] xlt95 - Microsoft Excel 95 Template \[.xlt] 相关资料 1.↑ http://dag.wieers.com/home-made/unoconv/ 转自：http://www.linux-wiki.cn/index.php/%E6%96%87%E6%A1%A3%E6%A0%BC%E5%BC%8F%E6%89%B9%E9%87%8F%E8%BD%AC%E6%8D%A2(doc,txt,pdf%E7%AD%89)#.E5.8D.95.E4.B8.AA.E6.96.87.E4.BB.B6.E8.BD.AC.E6.8D.A2 本文来自CSDN博客，转载请标明出处：http://blog.csdn.net/antony1029/archive/2010/04/30/5547767.aspx 官方网站: http://www.artofsolving.com/opensource/jodconverter 下载地点: 　　http://www.artofsolving.com/opensource/jodconverter 　　http://zh.openoffice.org/new/zh\_tw/downloads.html 　　目前版本: JODConverter v2.2.1, OpenOffice v3.0.0 　　使用需求: JDK1.4以上, 安装OpenOffice v2.0.3以上 　　基本简介: 　　JODConverter主要的功能是用来做各种档案的转换. 目前测试过, Word,Excel,PowerPoint转PDF都是没问题的. 　　因为JODConverter是透过OpenOffice来做转换, 所以使用前需要先安装OpenOffice, 并且将OpenOffice的Service启动, 才可以使用. OpenOffice.org具有一个鲜为人知的特性就是其能够作为一个服务来运行，而这种能力具有一定的妙用。举例来说，你可以把openoffice.og变成一个转换引擎，利用这种转换引擎你可以通过网络接口或命令行工具对文件的格式进行转换，JODConverter可以帮助你实现OpenOffice.org的这种文件转换功能。 为了将OpenOffice.org作为一个转换引擎，你必须以服务的方式将它启动，使它在某个特定的端口监听连接，在Linux平台你可以用如下的命令启动openoffice.org： soffice -headless -accept=”socket,port=8100;urp;”(我在linux下使用soffice -headless -accept=”socket,host=127.0.0.1,port=8100;urp;”，open office server是开启来了，但是文件转换不成功，异常是连接失败，这个很可以是你用jodconverter来转换时使用的是localhost，而当你的机有host配置文件里没有将localhost与127.0.0.1对应起来时，就无法解析了，这里可以修改host文件或去掉host=127.0.0.1，这样我试过可以成功) 在Windows平台, 使用如下命令： “C:\\Program Files\\OpenOffice.org 2.2\\program\\soffice” -accept=”socket,port=8100;urp;” 　　使用教学: 　　Step1: 安装OpenOffice 　　Step2: 启动OpenOffice Service 1 cd C:\\Program Files\\OpenOffice.org 3\\program 　 2 soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard 　　Step3:将JODConverter的Jar档放进专案中的Library, 请检查你的专案是否包含以下的Jar档: 　　jodconverter-2.2.1.jar 　　jurt-2.3.0.jar 　　xstream-1.2.2.jar 　　ridl-2.3.0.jar 　　commons-io-1.3.1.jar 　　juh-2.3.0.jar 　　slf4j-api-1.4.3.jar 　　unoil-2.3.0.jar 　　slf4j-jdk14-1.4.3.jar 　　Step4: 准备一个word档放在c:/document.rtf 　　Step5: 执行以下程式 Java代码 01.import java.io.File; 02. 03.　　import com.artofsolving.jodconverter.DocumentConverter; 04. 05.　　import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection; 06. 07.　　import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection; 08. 09.　　import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter; 10. 11.　　public class JodDemo { 12. 13.　　public static void main(String\[] args) throws Exception{ 14. 15.　　File inputFile = new File("c:/document.rtf"); 16. 17.　　File outputFile = new File("c:/document.doc"); 18. 19.　　// connect to an OpenOffice.org instance running on port 8100 20. 21.　　OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); 22. 23.　　connection.connect(); 24. 25.　　// convert 26. 27.　　DocumentConverter converter = new OpenOfficeDocumentConverter(connection); 28. 29.　　converter.convert(inputFile, outputFile); 30. 31.　　// close the connection 32. 33.　　connection.disconnect(); 34. 35.　　} 36. 37.　　} 程式说明: 　　程式的部份相当简洁, 特别要注意的地方是第12行连线的port必须与你启动OpenOffice的Port相同, 　　另外JODConverter预设是用副档名作文件种类的判断, 所以副档名必须要正确才行. 　 如果副档名比较特别的话, 就必须在convert()的时候强制指定Document Type. 心得: 　　JODConverter使用起来相当方便, 官网也提供War档让JODConverter变成Web Service提供给不同的语言来呼叫. 　　特别要注意的是, OpenOffice Service并不是ThreadSafe的, 多个Web AP在使用的时候必须要注意. 那我也來補充一些好了 之前也在試這個檔案轉換的程式 程式最好加上 try-catch 因為之前发現有些檔案 format 不能转，发生 Exception 后，connection 不會自动切断，程序会hand 住 所以改成如下方式： Java代码 01.public void convert(String input, String output){ 02. File inputFile = new File(input); 03. File outputFile = new File(output); 04. OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); 05. try { 06. connection.connect(); 07. DocumentConverter converter = new OpenOfficeDocumentConverter(connection); 08. converter.convert(inputFile, outputFile); 09. } catch(Exception e) { 10. e.printStackTrace(); 11. } finally { 12. try{ if(connection != null){connection.disconnect(); connection = null;}}catch(Exception e){} 13. } 14. } 再來，明明就是 open office 的檔案，卻生不能轉換的問題。例如：\*.STW, \*.SXD, \*.ODF 等，後來才知道可以自行指定來源檔和輸出檔的 mime-type，程式如下： Java代码 01.public void convertSTW(String input, String output){ 02. DocumentFormat stw = new DocumentFormat("OpenOffice.org 1.0 Template", DocumentFamily.TEXT, "application/vnd.sun.xml.writer", "stw"); 03. DefaultDocumentFormatRegistry formatReg = new DefaultDocumentFormatRegistry(); 04. DocumentFormat pdf = formatReg.getFormatByFileExtension("pdf"); 05. File inputFile = new File(input); 06. File outputFile = new File(output); 07. OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); 08. try { 09. connection.connect(); 10. DocumentConverter converter = new OpenOfficeDocumentConverter(connection); 11. converter.convert(inputFile, stw, outputFile, pdf); 12. } catch(Exception e) { 13. e.printStackTrace(); 14. } finally { 15. try{ if(connection != null){connection.disconnect(); connection = null;}}catch(Exception e){} 16. } 17. } 上面的程式是轉換 STW 到 PDF，如果是 SXD / ODF 則只需要變更 DocumentFormat 的內容即可。 Java代码 01.DocumentFormat sxd = new DocumentFormat("OpenOffice.org 1.0 Drawing", DocumentFamily.DRAWING, "application/vnd.sun.xml.sraw", "sxd"); 02. 03.DocumentFormat odf = new DocumentFormat("OpenDocument Math", DocumentFamily.TEXT, "application/vnd.oasis.opendocument.formula", "odf"); 所有 default support 的 DocumentFormat 都在 com.artofsolving.jodconverter.DefaultDocumentFormatRegistry 裡，但並非所有 open office 支援的 file format 都有，所以要像上面的方法自行去定义 DocumentFormat，至于它里面的参数可以从jodconverter-2.2.2.jar包的com.artofsolving.jodconverter包下的document-formats.xml文件里面得到，这样就可以完成多种格式的转换，如open office，ms office ， wps office及所有的纯文本文件。