TxtToRTF()

User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

TxtToRTF()

Post by byte-one »

Is there a function Text-Format 2 RTF-Format and visversa and other functions to manage the RTF-Format?
Thanks!
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: TxtToRTF()

Post 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

/*
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
 
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: TxtToRTF()

Post by byte-one »

James, thanks!
A good code! Meanwhile i found all required functions.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
Antonio Linares
Site Admin
Posts: 42599
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 41 times
Been thanked: 88 times
Contact:

Re: TxtToRTF()

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: TxtToRTF()

Post by nageswaragunupudi »

byte-one wrote:James, thanks!
A good code! Meanwhile i found all required functions.

Can you please share?
Regards

G. N. Rao.
Hyderabad, India
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: TxtToRTF()

Post 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.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: TxtToRTF()

Post by James Bott »

By GTF do you mean "gene transfer format?"
User avatar
reinaldocrespo
Posts: 981
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL
Been thanked: 1 time

Re: TxtToRTF()

Post 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.
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: TxtToRTF()

Post 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!
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: TxtToRTF()

Post 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?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: TxtToRTF()

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Antonio Linares
Site Admin
Posts: 42599
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 41 times
Been thanked: 88 times
Contact:

Re: TxtToRTF()

Post by Antonio Linares »

regards, saludos

Antonio Linares
www.fivetechsoft.com
MOISES
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Re: TxtToRTF()

Post 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.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: TxtToRTF()

Post 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
MOISES
Posts: 838
Joined: Wed Aug 22, 2007 10:09 am

Re: TxtToRTF()

Post by MOISES »

Up please!.
Saludos / Regards,

FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
Post Reply