Displaying formatted rich text

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

eddparsons
Ebase User
Posts: 53
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

Displaying formatted rich text

#1

Postby eddparsons » Thu Jun 20, 2013 3:36 pm

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}
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Thu Jun 20, 2013 4:47 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.

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);
    }
}
Regards
Jon
0 x

LKirby
Ebase User
Posts: 37
Joined: Wed Mar 13, 2013 11:33 am
Contact:

#3

Postby LKirby » Fri Jun 21, 2013 8:31 am

I had a go at this as I could have done with a similar thing before but in the log I got:

Code: Select all

<html>
  <head>
    <style>
      <!--
      -->
    </style>
  </head>
  <body>
    <p>
      
    </p>
  </body>
</html>
I tried it with a couple of different rtf documents and got the same thing each time. :(
0 x

Steve
Moderator
Moderator
Posts: 421
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

#4

Postby Steve » Fri Jun 21, 2013 9:28 am

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
0 x

eddparsons
Ebase User
Posts: 53
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

#5

Postby eddparsons » Thu Jun 27, 2013 1:07 pm

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
0 x

Steve
Moderator
Moderator
Posts: 421
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

#6

Postby Steve » Thu Jun 27, 2013 1:49 pm

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

Code: Select all

importPackage&#40;com.bhivef.lnrt2html&#41;;

var htmlText = RichText2Html.parse&#40;rtfText, "Error Message"&#41;; 
or you could invoke parse using the package name as well;

e.g

Code: Select all

var htmlText = com.bhivef.lnrt2html.RichText2Html.parse&#40;rtfText, "Error Message"&#41;; 

Kind regards

Steve
0 x

eddparsons
Ebase User
Posts: 53
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

#7

Postby eddparsons » Thu Jun 27, 2013 3:31 pm

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)
0 x

Steve
Moderator
Moderator
Posts: 421
Joined: Fri Sep 07, 2007 3:44 pm
Location: Sandy, UK
Contact:

#8

Postby Steve » Fri Jun 28, 2013 12:00 pm

Hi Edd,

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 3 guests