我的代码是这样的: File inputFile = new File("c:/build.xml"); File outputFile = new File("c:/111.pdf"); OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); connection.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(connection); converter.convert(inputFile, outputFile); connection.disconnect(); 执行 报异常: Exception in thread "main" java.lang.IllegalArgumentException: unknown document format for file: c:\build.xml at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.guessDocumentFormat(AbstractOpenOfficeDocumentConverter.java:121) at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:93) at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:74) at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:70) at com.teamsoft.toPDF.JodDemo.main(JodDemo.java:19)
可是iText能将所有格式的文件转成PDF么?
我的意思是能够打印的文件都能转成PDF!
cd C:\Program Files\OpenOffice.org 3\program
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
基本上任何文档OpenOffice 都可以打开。 支持了XML、微软的doc、Excel、ppt文件等格式。
在openoffice 打开后,可以导出为 PDF ,利用这点可以基本实现 lz的要求 1、安装OpenOffice 32、用以下命令启动OpenOffice服务
cd C:\Program Files\OpenOffice.org 3\program
soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard
你可能需要用到的资料:
http://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_2_1详细参数:
参数名 类型 含义 取值范围 默认值
UseLosslessCompression Boolean 是否使用无损图像压缩格式,例如PNG true / false false
Quality Integer JPEG输出质量 1-100 90
ReduceImageResolution Boolean 所有图片是否都按照<code>MaxImageResolution</code>设置的最大分辨率进行剪裁 true / false false
MaxImageResolution Integer 所有图片的最大分辨率数值(DPI) 75, 150, 300, 600, 1200 300
UseTaggedPDF Boolean 生成PDF文档的时候是否包含标记 true / false false
ExportNotes Boolean 是否输出备注内容 true / false false
ExportBooks Boolean 是否输出书签 true / false true
OpenBookLevels Integer 默认打开的书签级别 -1
ExportNotesPages Boolean 是否输出备注页(只对幻灯片文件有效) true / false false
UseTransitionEffects Boolean 是否输出过渡效果(只对幻灯片文件有效) true / false true
ExportFormFields Boolean 是否把表单字段输出为控件 true / false true
FormsType Integer 表单类型 "0 FDF
1 PDF
2 HTML
3 XML" 0
IsSkipEmptyPages Boolean 是否跳过空白页面(只对文档文件有效) true / false false
IsAddStream Boolean 是否在原有文件之后添加新内容 true / false false
HideViewerMenubar Boolean 是否隐藏菜单栏 true / false false
HideViewerToolbar Boolean 是否隐藏工具栏 true / false false
HideViewerWindowControls Boolean 是否隐藏窗口控制 true / false false
ResizeWindowToInitialPage Boolean 是否改变窗口大小以适应最初的页面 true / false false
CenterWindow Boolean 是否把窗口至于桌面中间 true / false false
OpenInFullScreenMode Boolean 是否以全屏方式打开 true / false false
DisplayPDFDocumentTitle Boolean 是否显示文档标题 true / false true
InitialView Integer 初始查看方式 "0 提纲和缩略图都不打开
1 只打开提纲
2 只打开缩略图" 0
Magnification Integer 缩放方式 "0 实际大小
1 适合整个页面
2 适合页面宽度
3 适合可见范围宽度
4 使用<code>Zoom</code>属性设置的缩放比缩放比率" 0
Zoom Integer 缩放比率 正整数 100
InitialPage Integer 初始打开的页码 1-最大页码 1
PageLayout Integer 页面显示布局 "0 根据阅读器的配置
1 单页
2 单页连续
3 双页(<code>FirstPageOnLeft</code>属性决定奇偶页的左右位置)" 0
FirstPageOnLeft Boolean 双页显示的时候是否将第一页至于左侧 true / false false
Printing Integer 打印设置 "0 不能打印
1 以低分辨率(150DPI)打印
2 以高分辨率(300DPI)打印" 2
Changes Integer 是否允许变更文档 "0 不能变更
1 可以进行插入、删除、旋转操作
2 可以进行表单填写操作
3 可以进行表单填写和评论操作
4 以上操作都可以,但是不能复制" 4
EnableCopyingOfContent Boolean 是否允许复制内容 true / false true
EnableTextAccessForAccessibilityTools Boolean 是否允许辅助工具进行文字访问 true / false true
SelectPdfVersion Integer 文档版本 "0 PDF 1.4
1 PDF/A-1" 0
ExportLinksRelativeFsys Boolean 是否输出本地相对路径的超链接(file://协议) true / false false
PDFViewSelection Integer 定义PDF文档被用户查看的方式 "0 所有外部链接都会被输出为URI
1 该PDF文档只会在PDF阅读器内打开,只适用于PDF/A-1格式(即<code>SelectPdfVersion</code>为1)
2 该PDF文档会在浏览器内利用插件打开。输出的URI书签会兼容PDF输出特性<code>ExportBooksToPDFDestination</code>
" 0
ConvertOOoTargetToPDFTarget Boolean 是否把带有.od[tpgs]扩展名的目标文件转换为.pdf,源文件不会变化 true / false false
ExportBooksToPDFDestination Boolean 是否把OpenOffice.org源文件中的书签作为命名目标输出到PDF文档中 true / false false
群号100753590
希望在此群能帮助大家解决所需的问题。
感谢回帖!!!
File inputFile = new File("c:/build.xml");
File outputFile = new File("c:/111.pdf");
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
connection.connect();
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
connection.disconnect();
执行 报异常:
Exception in thread "main" java.lang.IllegalArgumentException: unknown document format for file: c:\build.xml
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.guessDocumentFormat(AbstractOpenOfficeDocumentConverter.java:121)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:93)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:74)
at com.artofsolving.jodconverter.openoffice.converter.AbstractOpenOfficeDocumentConverter.convert(AbstractOpenOfficeDocumentConverter.java:70)
at com.teamsoft.toPDF.JodDemo.main(JodDemo.java:19)
而是用convert(File, File, DocumentFormat) DocumentFormat docFormat = new DocumentFormat("Portable Document Format",
"application/pdf", "pdf");
// 过滤器
docFormat.setExportFilter(DocumentFamily.TEXT, "writer_pdf_Export");
// 导出参数
docFormat.setExportOption(DocumentFamily.TEXT,,
"FilterData",
...);过滤器里面的参数,第一个,代表是哪种类型的文档,后面,那个要参考我给你的超链接导出参数可以参考我给你的那个中文部分,不过一般全用默认。你留个email,我给你一些我以前的代码。不过,你要自己抽取出来。
其他格式的mime-type都能找到,为啥找不到XML的呢?
application/xml
试试看
File txtFile = File.createTempFile(xmlFile.getName(), ".txt");
...copy
...convert(txtFile, ....)
text/xml
application/xml
都不行,报错!
java.net.ConnectException: connection failed: socket,host=localhost,port=8100,tcpNoDelay=1: java.net.ConnectException: Connection refused: connect
at com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection.connect(AbstractOpenOfficeConnection.java:79)
at com.teamsoft.toPDF.JodDemo.main(JodDemo.java:25)麻烦帮忙解决!
我给你的那个JODConverter的网站(artofsolving.com?)里面有一个如何将OpenOffice设置为开机自启服务的方式。需要下载WindowsResourcesTool工具,然后个人经验,
1 先把启动命令写个bat,然后按指示,srvany.exe启动bat作为服务内容
2 服务启动的账号最好定为Administrator之类的管理员账号,而不是System服务账号,否则可能运行不了。
您好,能不能也给我发一份您以前写的代码: [email protected]
有没有办法不要在java中直接让OpenOffice运行起来呢,并且随时监测OpenOffice是否正常运行?