TxtToRTF()
TxtToRTF()
Is there a function Text-Format 2 RTF-Format and visversa and other functions to manage the RTF-Format?
Thanks!
Thanks!
- James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: TxtToRTF()
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
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
- 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()
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
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
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: TxtToRTF()
byte-one wrote:James, thanks!
A good code! Meanwhile i found all required functions.
Can you please share?
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: TxtToRTF()
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.
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.
- James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
- reinaldocrespo
- Posts: 981
- Joined: Thu Nov 17, 2005 5:49 pm
- Location: Fort Lauderdale, FL
- Been thanked: 1 time
Re: TxtToRTF()
Hi everyone;
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.
What is GTF format? Is there a class like RichText(). Please share the code. Thank you.
Reinaldo.
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()
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!
It can handle texts with different textcolors, fonts and aligns word for word or paragraph. RTF is much more complex!
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: TxtToRTF()
Reinaldo
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?
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
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: TxtToRTF()
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.
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
G. N. Rao.
Hyderabad, India
- 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()
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.
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
FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
- James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: TxtToRTF()
Rao,
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
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