Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can convert HTML to RTF using basic Java APIs <code>RTFEditorKit</code> and <code>HTMLEditorKit</code>. It is not converting new line tags like <code>&lt;br/&gt;</code> and <code>&lt;p&gt;</code> to new line character equivalent in RTF. I have applied external fix for that as shown in following Java code.</p> <pre><code>private static String convertToRTF(String htmlStr) { OutputStream os = new ByteArrayOutputStream(); HTMLEditorKit htmlEditorKit = new HTMLEditorKit(); RTFEditorKit rtfEditorKit = new RTFEditorKit(); String rtfStr = null; htmlStr = htmlStr.replaceAll("&lt;br.*?&gt;","#NEW_LINE#"); htmlStr = htmlStr.replaceAll("&lt;/p&gt;","#NEW_LINE#"); htmlStr = htmlStr.replaceAll("&lt;p.*?&gt;",""); InputStream is = new ByteArrayInputStream(htmlStr.getBytes()); try { Document doc = htmlEditorKit.createDefaultDocument(); htmlEditorKit.read(is, doc, 0); rtfEditorKit .write(os, doc, 0, doc.getLength()); rtfStr = os.toString(); rtfStr = rtfStr.replaceAll("#NEW_LINE#","\\\\par "); } catch (IOException e) { e.printStackTrace(); } catch (BadLocationException e) { e.printStackTrace(); } return rtfStr; } </code></pre> <p>Here, I am replacing new line equivalent HTML tags to some special string and replacing back to new line representation chars sequence <strong>\par</strong> in RTF.</p> <p>If you want to use more effective APIs and you have valid html, you should explore Apache-FOP.</p> <p>Apache FOP can be used to convert to RTF. Following are some useful links - </p> <p><a href="http://www.torsten-horn.de/techdocs/java-xsl.htm#XSL-FO-Java" rel="nofollow">http://www.torsten-horn.de/techdocs/java-xsl.htm#XSL-FO-Java</a></p> <p><a href="http://html2fo.sourceforge.net/index.html" rel="nofollow">http://html2fo.sourceforge.net/index.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload