如何在 Java 中转换 HTML ==> RTF?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3755230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert HTML ==> RTF in Java?
提问by Duprat
The basic API of JAVA that uses RTFEditorKit and HTMLEditorKit, is not able of recognize tags like <br/>
and <table>
.
So I have searched on internet a better way of converting HTML to RTF and i have found two solutions that seem to work.
JODConverter and HTML-to-RTFconverter. The first one needs OppenOffice installed to work and the second one uses DLL, so it can't be used on Linux.
使用 RTFEditorKit 和 HTMLEditorKit 的 JAVA 基本 API 无法识别<br/>
和<table>
. 所以我在互联网上搜索了一种将 HTML 转换为 RTF 的更好方法,我发现了两个似乎有效的解决方案。JODConverter 和 HTML-to-RTFconverter。第一个需要安装 OppenOffice 才能工作,第二个使用 DLL,所以它不能在 Linux 上使用。
Does anyone know about other solution?
有谁知道其他解决方案?
Thanks for any help!!!!
谢谢你的帮助!!!!
回答by Christian Kuetbach
If it is valid html, you can use Apache-FOP.
如果它是有效的 html,则可以使用 Apache-FOP。
There are stylesheets for transforming html to FO.
有用于将 html 转换为 FO 的样式表。
Apache FOP can write PDF and RTF as well.
Apache FOP 也可以编写 PDF 和 RTF。
http://www.torsten-horn.de/techdocs/java-xsl.htm#XSL-FO-Java
http://www.torsten-horn.de/techdocs/java-xsl.htm#XSL-FO-Java
回答by jqa
Do they want it in RTF or do they want it in Word format? There's a big difference.
他们想要 RTF 格式还是 Word 格式?有很大的不同。
Ensure your editor is generating XHTML (or convert it yourself with jtidy, htmlcleanup etc) then download the content as an XHTML but with a .doc extension and the MS Word mime type. Word 2003 or higher will open it as a word doc.
确保您的编辑器正在生成 XHTML(或使用 jtidy、htmlcleanup 等自行转换),然后将内容下载为 XHTML,但带有 .doc 扩展名和 MS Word mime 类型。Word 2003 或更高版本会将其作为 Word 文档打开。
回答by zfr
By RTF conversion there is an important issue to care about: a target RTF viewer. All of them declare RTF support, but, for instance, Notepad.exe can only show images in WMF format, it does not display headers and footers. TextEdit on MacOS can only deal with images embedded as a kind of active objects and has troubles with tables, OpenOffice is not tolerant to minor markup inconsistencies etc.
通过 RTF 转换,需要关注一个重要问题:目标 RTF 查看器。它们都声明支持 RTF,但例如 Notepad.exe 只能显示 WMF 格式的图像,它不显示页眉和页脚。MacOS 上的 TextEdit 只能处理作为一种活动对象嵌入的图像,并且有表格问题,OpenOffice 不能容忍轻微的标记不一致等。
My favorite tool for HTML->RTF conversion is PD4ML- it produces clean, almost human-readable RTF markup and successfully solves another challenging problem for RTF generating tool - a support of nested tables (if you work with HTML - they are everywhere).
我最喜欢的HTML->RTF 转换工具是PD4ML——它生成干净、几乎人类可读的 RTF 标记,并成功解决了 RTF 生成工具的另一个具有挑战性的问题——支持嵌套表(如果你使用 HTML——它们无处不在)。
回答by Grieih
You can take a look at RTF Template (http://rtftemplate.sourceforge.net/) Don't know if it fits your needs, but I used several times under Linux and was OK.
你可以看看RTF模板(http://rtftemplate.sourceforge.net/)不知道是否符合你的需求,但我在Linux下使用了几次,都可以。
回答by William Witter da Silva
I already used the html-to-pdf and got the expected result. I have helped.
我已经使用了 html-to-pdf 并得到了预期的结果。我有帮助。