How to convert HTML ==> RTF in Java?
Asked Answered
R

5

8

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.

Does anyone know about other solution?

Thanks for any help!!!!

Ruano answered 20/9, 2010 at 20:30 Comment(0)
H
3

If it is valid html, you can use Apache-FOP.

There are stylesheets for transforming html to FO.

Apache FOP can write PDF and RTF as well.

http://www.torsten-horn.de/techdocs/java-xsl.htm#XSL-FO-Java

http://html2fo.sourceforge.net/index.html

Harlan answered 23/9, 2010 at 21:53 Comment(0)
R
3

Do they want it in RTF or do they want it in Word format? There's a big difference.

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.

Resistor answered 6/10, 2010 at 2:49 Comment(2)
I have tried this option today. It worked as you said. I didn't know that Microsoft Word and OpenOffice were able of converting HTML --> RTF. Thank you so much my friend!Ruano
Great tip! Even better if you use content type "application/vnd.openxmlformats-officedocument.wordprocessingml.document" and .docxEndosteum
C
0

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.

Cirrose answered 20/9, 2010 at 20:39 Comment(1)
I have a HTML editor (richfaces) that generates a HTML output and I need to convert it to RTF. I think RTF Template won’t help. Thanks for helping!Ruano
S
0

I already used the html-to-pdf and got the expected result. I have helped.

Softcover answered 20/9, 2010 at 20:44 Comment(0)
K
0

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.

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).

Kendalkendall answered 6/6, 2013 at 11:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.