Hi,
I have some rich text stored in a database (example below) that I want to output on an Ebase page. Is there a way of displaying this with formatting?
Regards,
Edd
{\rtf1\ansi\ansicpg1252\uc1\deff0{\fonttbl
{\f0\fswiss\fcharset0\fprq2 Arial;}
{\f1\froman\fcharset2\fprq2 Symbol;}}
{\colortbl;\red0\green0\blue0;\red255\green255\blue255;\red255\green255\blue255;}
{\stylesheet{\s0\itap0\f0\fs24 [Normal];}{\*\cs10\additive Default Paragraph Font;}}
{\*\generator TX_RTF32 12.0.500.502;}
\deftab1134\paperw12240\paperh15840\margl1800\margt1440\margr1800\margb1440
{\*\background{\shp{\*\shpinst\shpleft0\shptop0\shpright0\shpbottom0\shpfhdr0\shpbxmargin\shpbxignore\shpbymargin\shpbyignore\shpwr0\shpwrk0\shpfblwtxt1\shplid1025{\sp{\sn shapeType}{\sv 1}}{\sp{\sn fFlipH}{\sv 0}}{\sp{\sn fFlipV}{\sv 0}}{\sp{\sn fillColor}{\sv 16777215}}{\sp{\sn fFilled}{\sv 1}}{\sp{\sn lineWidth}{\sv 0}}{\sp{\sn fLine}{\sv 0}}{\sp{\sn fBackground}{\sv 1}}{\sp{\sn fLayoutInCell}{\sv 1}}}}}\pard\itap0\plain\f0\fs20 Not Restricted\plain\f0\fs20\b\cf3 tate whether access to the premises by children is restricted or prohibitedState whether access to the premises by children is restricted or prohibited}
Displaying formatted rich text
Moderators: Jon, Steve, Ian, Dave
-
- Ebase User
- Posts: 53
- Joined: Wed Jan 02, 2013 4:23 pm
- Location: Lyndhurst, Hampshire
- Contact:
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Edd,
You might try this rtfToHtml Javascript function, I got it from Google and converted it from Java to Javascript. Once you've got your rtf text, you could display it in a Text Control as shown below. You need to make sure that the Contains HTML option is checked for the Text Control. I tried this with your RTF text and it gave an answer but not the one I was expecting. But I suspect that was because the RTF text can't simply be copy/pasted.
Regards
Jon
You might try this rtfToHtml Javascript function, I got it from Google and converted it from Java to Javascript. Once you've got your rtf text, you could display it in a Text Control as shown below. You need to make sure that the Contains HTML option is checked for the Text Control. I tried this with your RTF text and it gave an answer but not the one I was expecting. But I suspect that was because the RTF text can't simply be copy/pasted.
Code: Select all
var rtfText = ".....";
var htmlText = rtfToHtml(rtfText);
log(htmlText );
controls.TEXT1.text.text = htmlText ;
function rtfToHtml(rtfText)
{
var sr = new java.io.StringReader(rtfText);
var p = new javax.swing.JEditorPane();
p.setContentType("text/rtf");
var kitRtf = p.getEditorKitForContentType("text/rtf");
try
{
kitRtf.read(sr, p.getDocument(), 0);
kitRtf = null;
var kitHtml = p.getEditorKitForContentType("text/html");
var writer = new java.io.StringWriter();
kitHtml.write(writer, p.getDocument(), 0, p.getDocument().getLength());
return writer.toString();
}
catch (e)
{
log(e);
}
}
Jon
0 x
-
- Ebase User
- Posts: 37
- Joined: Wed Mar 13, 2013 11:33 am
- Contact:
I had a go at this as I could have done with a similar thing before but in the log I got:
I tried it with a couple of different rtf documents and got the same thing each time. 
Code: Select all
<html>
<head>
<style>
<!--
-->
</style>
</head>
<body>
<p>
</p>
</body>
</html>

0 x
-
- Moderator
- Posts: 421
- Joined: Fri Sep 07, 2007 3:44 pm
- Location: Sandy, UK
- Contact:
Hi
I think you may need some third party solution. I have not tested this, but you could download and compile this:
https://code.google.com/p/lnrt2html/sou ... l.java?r=1
You will need to put the compiled class in:
<ebase__install>/UfsServer/tomcat/webapps/ufs/WEB_INF/classes
You can then invoke this class using the Server Side JavaScript.
Steve
I think you may need some third party solution. I have not tested this, but you could download and compile this:
https://code.google.com/p/lnrt2html/sou ... l.java?r=1
You will need to put the compiled class in:
<ebase__install>/UfsServer/tomcat/webapps/ufs/WEB_INF/classes
You can then invoke this class using the Server Side JavaScript.
Steve
0 x
-
- Ebase User
- Posts: 53
- Joined: Wed Jan 02, 2013 4:23 pm
- Location: Lyndhurst, Hampshire
- Contact:
Thanks for your suggestion Steve.
I have compiled the class, saved in folder classes\com\bhivef\lnrt2html folder and impoted the class in a javascript using:
importPackage(com.bhivef.lnrt2html.*);
How do I then use this?
I've tried using:
var htmlText = RichText2Html(rtfText);
but I get the following:
ReferenceError: "RichText2Html" is not defined
As you may be able to tell I haven't really got a clue what I'm doing - any pointers would be gratefully received.
Regards,
Edd
I have compiled the class, saved in folder classes\com\bhivef\lnrt2html folder and impoted the class in a javascript using:
importPackage(com.bhivef.lnrt2html.*);
How do I then use this?
I've tried using:
var htmlText = RichText2Html(rtfText);
but I get the following:
ReferenceError: "RichText2Html" is not defined
As you may be able to tell I haven't really got a clue what I'm doing - any pointers would be gratefully received.
Regards,
Edd
0 x
-
- Moderator
- Posts: 421
- Joined: Fri Sep 07, 2007 3:44 pm
- Location: Sandy, UK
- Contact:
Hi,
When you import the package, you do not need to .* at the end. You are also wanting to call a static method, so you do not need to create a new instance of the Java Object. You want to invoke the method directly.
e.g
or you could invoke parse using the package name as well;
e.g
Kind regards
Steve
When you import the package, you do not need to .* at the end. You are also wanting to call a static method, so you do not need to create a new instance of the Java Object. You want to invoke the method directly.
e.g
Code: Select all
importPackage(com.bhivef.lnrt2html);
var htmlText = RichText2Html.parse(rtfText, "Error Message");
e.g
Code: Select all
var htmlText = com.bhivef.lnrt2html.RichText2Html.parse(rtfText, "Error Message");
Kind regards
Steve
0 x
-
- Ebase User
- Posts: 53
- Joined: Wed Jan 02, 2013 4:23 pm
- Location: Lyndhurst, Hampshire
- Contact:
Ok, I have the importPackage(com.bhivef.lnrt2html);
Then using
var htmlText = RichText2Html.parse(rtfText, "Error Message");
I get the same RichText2Html not defined error.
Using
var htmlText = com.bhivef.lnrt2html.RichText2Html.parse(rtfText, "Error Message");
I get the error below:
org.mozilla.javascript.EcmaError: TypeError: Cannot call property parse in object [JavaPackage com.bhivef.lnrt2html.RichText2Html]. It is not a function, it is "object". (RICHTEXTTEST#5)
Then using
var htmlText = RichText2Html.parse(rtfText, "Error Message");
I get the same RichText2Html not defined error.
Using
var htmlText = com.bhivef.lnrt2html.RichText2Html.parse(rtfText, "Error Message");
I get the error below:
org.mozilla.javascript.EcmaError: TypeError: Cannot call property parse in object [JavaPackage com.bhivef.lnrt2html.RichText2Html]. It is not a function, it is "object". (RICHTEXTTEST#5)
0 x
-
- Moderator
- Posts: 421
- Joined: Fri Sep 07, 2007 3:44 pm
- Location: Sandy, UK
- Contact:
Hi Edd,
Can you email the RichText2Html.java file to support@ebasetech.com and I will have a look for you.
Kind regards
Steve
Can you email the RichText2Html.java file to support@ebasetech.com and I will have a look for you.
Kind regards
Steve
0 x
Who is online
Users browsing this forum: No registered users and 17 guests