Page 1 of 2

TxtToRTF()

PostPosted: Tue Jan 13, 2015 12:59 pm
by byte-one
Is there a function Text-Format 2 RTF-Format and visversa and other functions to manage the RTF-Format?
Thanks!

Re: TxtToRTF()

PostPosted: Tue Jan 13, 2015 3:33 pm
by James Bott
Here is one from my notes. Reinaldo seems to know a lot about it. You might also search the forum if you haven't already.

James

Code: Select all  Expand view
/*
Author: Reinaldo Crespo-Bazán
Date   : 10/25/2010
Source: viewtopic.php?f=3&t=15270
Note: Convert RTF text to plain text
*/


#DEFINE _cREGEX "\{?\\([a-z]{1,32}[0-9]* ?)([A-z, ]*;)?|}"  //includes fonts

function GetTextFromRTF( cRtfText, lKeepCRLFs )
    local aRet
    local cStrip, i

    DEFAULT cRtfText := ""
    DEFAULT lKeepCRLFs := .t.
   
    aRet := hb_RegExAll( _cREGEX, cRtfText, .f. )

    if aRet == Nil  ;return cRtfText    ;endif
   
    aSort( aRet,,, { |x,y| len( x[1] ) > len( y[1] ) } )
    for i := 1 to len( aRet )

        cRtfText := StrTran( cRtfText, aRet[ i, 1 ], "" )
       
    Next
   
    if !lKeepCRLFs
        cRtfText := StrTran( cRtfText, CRLF, " " )
    endif

Return cRtfText
 

Re: TxtToRTF()

PostPosted: Wed Jan 14, 2015 8:05 am
by byte-one
James, thanks!
A good code! Meanwhile i found all required functions.

Re: TxtToRTF()

PostPosted: Wed Jan 14, 2015 2:36 pm
by Antonio Linares
Günther,

If you want to convert a RTF into standard text, then using a RichEdit control, you could do this:

oRichEdit:LoadRTF( cRTFText ) // RTF

MsgInfo( oRichEdit:GetText() ) // standard text

Re: TxtToRTF()

PostPosted: Wed Jan 14, 2015 11:16 pm
by nageswaragunupudi
byte-one wrote:James, thanks!
A good code! Meanwhile i found all required functions.

Can you please share?

Re: TxtToRTF()

PostPosted: Thu Jan 15, 2015 3:49 pm
by byte-one
Thanks to all!
In the meantime after tests i found, that many problems are waiting for me, using RTF for my project. Now i explored the GTF-Format. This is for me the right way as the complete source is reachable and no DLL is required.

Re: TxtToRTF()

PostPosted: Thu Jan 15, 2015 5:49 pm
by James Bott
By GTF do you mean "gene transfer format?"

Re: TxtToRTF()

PostPosted: Thu Jan 15, 2015 6:29 pm
by reinaldocrespo
Hi everyone;

oRichEdit:GetText()


Yes GetText() method works best but requires to initialize the object which will require a dialog or window. When working on the background , when pulling text from a Blob field or when no RichText object is needed, then my function GetTextFromRTF() is the only choice.

Now i explored the GTF-Format


What is GTF format? Is there a class like RichText(). Please share the code. Thank you.


Reinaldo.

Re: TxtToRTF()

PostPosted: Thu Jan 15, 2015 10:41 pm
by byte-one
Reinaldo, GTF is part from FW! See FORMAT GET.
It can handle texts with different textcolors, fonts and aligns word for word or paragraph. RTF is much more complex!

Re: TxtToRTF()

PostPosted: Thu Jan 15, 2015 11:50 pm
by nageswaragunupudi
Reinaldo

Yes GetText() method works best but requires to initialize the object which will require a dialog or window. When working on the background , when pulling text from a Blob field or when no RichText object is needed, then my function GetTextFromRTF() is the only choice.

Your function works very well in most cases, but was failing when the rtf contained embedded tables and other objects. Have you improved it recently?

Re: TxtToRTF()

PostPosted: Fri Jan 16, 2015 1:51 am
by nageswaragunupudi
Once we create a richedit control (we can even use a hidden window) it is very easy to convert text to rtf or rtf to text. It is much better to have a function like Reinaldo's which works in all cases.

I am also looking for it there is any way to "render" rtf and html in a rectangle (not a control). I greatly appreciate any suggestions.

Re: TxtToRTF()

PostPosted: Fri Jan 16, 2015 5:23 am
by Antonio Linares

Re: TxtToRTF()

PostPosted: Fri Mar 13, 2015 3:46 pm
by MOISES
Hello,

I am searching too a function like this one, but with accent support, lists, bullets, boxes, pictures, etc to be removed.

Is there an update?.

Thank you very much.

Re: TxtToRTF()

PostPosted: Fri Mar 13, 2015 6:41 pm
by James Bott
Rao,

I am also looking for it there is any way to "render" rtf and html in a rectangle (not a control). I greatly appreciate any suggestions.


What do you mean by a rectangle? Just an enclosed area?

Why can't it be a control?

You could probably use a window, dialog, or TPanel object.

James

Re: TxtToRTF()

PostPosted: Tue Mar 17, 2015 8:51 pm
by MOISES
Up please!.