Manipulating Rich Text fields

Author: ncolmart@medinfo.fr (ncolmart)

Hi all,
I have a Rich text field containing the rtf tags, and I would like to copy it in a standard text field without the rtf tags.
Has anyone an idea how to perform that ?

When I assign my standard field with the Rich text field, all rtf tags are included.
But when I manually select the text from the Rich text field, copy and paste it in the standard field, all rtf tags are removed. But how can I do it automatically with Uniface ?

Thanks

6 Comments

  1. not quite sure, but I think I saw someting in the $encode/$decode or $string area (undocumented issue, as usual)


    Author: ulrich-merkel (ulrichmerkel@web.de)
  2. long time ago, I found the following small C-code
    perhaps someone can create a nice little DLL out of it and may share it with us:

    /*
            rtf2ascii.c - convert rtf to ascii
            coded in 1994 by Felix Rauch
            felix@nice.ch
    */

    #include <stdio.h>

    FILE *in;

    void scanblock(void)    /* scan a block in `{}' */
    {
        int c;
        while(!feof(in) && ((c = fgetc(in)) != '}')) {
            if(c == '{')
                scanblock();
        }
    }

    int scanpart(void)      /* return 1 if text follows, otherwise 0 */
    {
        int c;
        while(!feof(in)) {
            c = fgetc(in);
            if(c == ' ')    /* the rest until '\n' is test */
                return 1;
            else if(c == '\n')      /* end of command-part */
                return 0;
            else if(c == '\{')      /* skip whole block */
                scanblock();
        }
        return 0;   /* not reached if there are no errors */
    }

    void scantext(void)     /* scan text until '\n' */
    {
        int c;
        while(!feof(in) && ((c = fgetc(in)) != '\n')) {
            if(c == '\\')   /* escape char */
                c = fgetc(in);
            fputc(c, stdout);
        }
    }

    void main(int argc, char *argv[])
    {
        int i, c, ret;
        char rtfc[7] = "{\\rtf0";

        if(argc == 1)
            in = stdin;
        else if(argc == 2)
            in = fopen(argv[1], "r");
        for(i = 0; i < 6; i++) {            /* rtf-magic-cookie test */
            if(fgetc(in) != rtfc[i]) {
                puts("not in rtf-format");
                exit(1);
            }
        }
        while(!feof(in)) {
            ret = 2;        /* no command part or block found yet */
            c = fgetc(in);
            if(c == '\\') {
                ret = scanpart();   /* command part */
            }
            else if(c == '\{') {    /* block found */
                scanblock();
                ret = 0;
                if((c = fgetc(in)) != '\n') /* a '\n' after a block must be ignored */
                    ungetc(c, in);
            }
            else if(c == '}') {     /* end of rtf-stream */
                break;
            }
            if(ret > 0) {   /* if there's text after a command part or just text */
                if(ret == 2)        /* if just text, the print first char */
                    fputc(c, stdout);  /* (otherwise it's a '//' */
                scantext();         /* text block */
            }
        }
        exit(0);            /* that's all, dude */
    }
     


    Author: ulrich-merkel (ulrichmerkel@web.de)
  3. and i found another more "basic" routine at: http://www.infionline.net/~wtnewton/batch/rtf2txt.htm

    RTF2TXT.BAT - RTF to Text file converter

    A program born out of a simple need, to read a Rich Text Format document. This batch creates and runs a QBasic program that converts the RTF file to plain text. Changes "\par" to newline, "\tab" to tab, all other words beginning with "\" are ignored. Newlines in the source file are ignored. To get rid of the header junk, "{" turns off the output stream until a "}" comes along.

    basic code attached to the pagh


    Author: ulrich-merkel (ulrichmerkel@web.de)
  4. I had to use a MS Word COM callout to convert RTF text to plain text.

    HTH,

    Larry


    Author: hoss (adkinsl@proware.com)
  5. The convertion with word is very slow.

    In the Downloads, I puted the code to make the convertion with Java under Oracle. It works only with Oracle because, you can implement a procedure or function who launch java class.

    Regards,

    Antoine


    Author: apicaud (antoine.picaud@free.fr)
  6. Thanks to all.
    I'll try your solutions.

    Regards,
    Nicolas


    Author: ncolmart (ncolmart@medinfo.fr)