Uniface User Forum

 View Only
  • 1.  Removing RTF control characteres from field

    Posted 07-05-2021 21:01

    First of all, I´m happy to working with Uniface again, after almost two years.


    Dear all,

    I have an entity that has a field defined as C* (in Oracle CLOB), and RICHEDITBOX as widget. Now, this field should be access from outside Uniface. How can I create another field without RTF controls that are stored when RICHEDITBOX is used widget? Any idea is welcome.

    Uniface 9.7.04 + Oracle.

    Thank you in advance,

    Marcelo Martins



  • 2.  RE: Removing RTF control characteres from field

    PARTNER
    Posted 07-05-2021 21:06

    Well, we mostly make text rtf rather than the other way around, but the rtf characters are all (pretty much) straight ascii character sequences, so a series of $replace statements should remove the ones people use.



  • 3.  RE: Removing RTF control characteres from field

    Posted 07-06-2021 08:03

    Hi Marcelo,

    there is a UNRTF utility in the gnu world to convert RTF file/stream to other formats, including pure text. It is available in the standard Linux repo. I suggest to search for its implementations to incapsulate its work in a Uniface components.

    Hope it helps.

    Gianni



  • 4.  RE: Removing RTF control characteres from field

    ROCKETEER
    Posted 07-06-2021 10:55
    Edited by Daniel Iseli 03-15-2022 05:23

    You also could use the HTML widget, and do the RTF conversion using JavaScript and Regular Expressions. You should be able to find numerous samples on the Internet.

    I've once made a sample that looked like this:

    The following blockdata is assigned to a field that uses the HTML widget:

    html1:blockdata ~
    

    <!DOCTYPE html>
    <html>
    <body>

    <p id="plainText"></p>

    <script>
    function convertToPlain(rtf) {
    rtf = rtf.replace(/\\par[d]?/g, "");
    rtf = rtf.replace(/\{\*?\\[^{}]+}|[{}]|\\\n?[A-Za-z]+\n?(?:-?\d+)?[ ]?/g, "").trim();
    rtf = rtf.replace(/\n/g, "<br/>")
    window.unifaceTriggers('getPlainText', rtf);
    }
    </script>

    </body>
    </html>~

    You then pass the RTF-text to the HTML widget like this:

    $fieldhandle(HTML1)->$widgetoperation("JS:convertToPlain", RTF1)

    And from the JavaScript function the extended trigger getPlainText is called that is defined for the HTML widget field: 

    trigger getPlainText
    params
        string plainTXT : IN
    endparams
    
    TXT1.DUM = $replace(plainTXT, 1, "<br/>", "%%^", -1)
    
    end;- getPlainText trigger

    My test form contains three fields:

    • RTF1.DUMMY: Rich Edit Box widget with RTF-text
    • HTML1.DUMMY: HTML widget (can be hidden)
    • TXT1.DUM: normal Edit Box that will show the extracted text.

    This should also work with Uniface 9.7.04. And the advantage of this approach is that you don't need any external dependencies.

    I hope this helps.

    Kind reagrds,
    Daniel



  • 5.  RE: Removing RTF control characteres from field

    Posted 07-06-2021 12:25

    Thank you,  guys. You help me a lot. I´ll play with your suggestions..