Which DATA or METHOD in a rtf class should be used to get the content in plain text (without changing the actual content)?
TIA
How to obtain plain text from a RTF control?
Re: How to obtain plain text from a RTF control?
hi,
i have search but not found Constant EM_SETTEXTMODE under FiveWin
you can try this HB_FUNC()
mode can be
https://learn.microsoft.com/de-de/windows/win32/controls/em-settextmode
i have search but not found Constant EM_SETTEXTMODE under FiveWin
![Surprised :o](./images/smilies/icon_surprised.gif)
you can try this HB_FUNC()
Code: Select all | Expand
// RichEditBox_SetRTFTextMode ( hWndControl, lRTF )
HB_FUNC ( RICHEDITBOX_SETRTFTEXTMODE )
{
HWND hWndControl = (HWND) HMG_parnl (1);
BOOL lRTF = ( HB_ISLOG (2) ? (BOOL) hb_parl (2) : TRUE );
LONG Mode = ( lRTF ? TM_RICHTEXT : TM_PLAINTEXT ) | TM_MULTILEVELUNDO | TM_MULTICODEPAGE;
SendMessage ( hWndControl, EM_SETTEXTMODE, (WPARAM) Mode, 0 );
}
mode can be
TM_PLAINTEXT
TM_RICHTEXT
https://learn.microsoft.com/de-de/windows/win32/controls/em-settextmode
greeting,
Jimmy
Jimmy
Re: How to obtain plain text from a RTF control?
Dear Jimmy
The function that you indicate can only be used if the control is empty, that is, if it does not already contain any text, to indicate to the control the type of text that it is going to contain.
(Correct me if my opinion is not correct)
From:
https://learn.microsoft.com/en-us/windo ... ettextmode
What the companion requests is to be able to remove all the formatting tags used by the control and obtain the text contained in the control without any formatting ( plain text ).
I will study if it is possible, although the method does exist
that is possible, make it easy to get the text
There is also the possibility of using Word ( OLE ) which has the function "SAVE AS TEXT WITHOUT FORMAT"
The function that you indicate can only be used if the control is empty, that is, if it does not already contain any text, to indicate to the control the type of text that it is going to contain.
(Correct me if my opinion is not correct)
From:
https://learn.microsoft.com/en-us/windo ... ettextmode
Sets the text mode or undo level of a rich edit control. The message fails if the control contains any text.
What the companion requests is to be able to remove all the formatting tags used by the control and obtain the text contained in the control without any formatting ( plain text ).
I will study if it is possible, although the method does exist
METHOD SaveAsHtml( cFile ) CLASS TRichEdit5
that is possible, make it easy to get the text
There is also the possibility of using Word ( OLE ) which has the function "SAVE AS TEXT WITHOUT FORMAT"
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Re: How to obtain plain text from a RTF control?
This is a function that does a good conversion (still not perfect though)
Code: Select all | Expand
#include "Fivewin.ch"
Function Main()
? SaveRtfAsTxt( ".\Tutorial2.rtf" )
Return nil
//----------------------------------------------------------------------------//
Function SaveRtfAsTxt( cFile )
local aTags
local cTag
local cRtf
local aElems
local x
local y
if File( cFile )
cRtf := hb_MemoRead( cFile )
aTags := hb_RegExAll( "{\*?\\.+(;})|\s?\\[A-Za-z0-9]+|\s?{\s?\\[A-Za-z0-9]+\s?|\s?}\s?", cRtf )
XBrowse( aTags )
For each aElems in aTags
For x = 1 to Len( aElems )
if Valtype( aElems[ x ] ) = "A"
For y = 1 to Len( aElems[ x ] )
if Valtype( aElems[ x ][ y ] ) = "C"
cTag := aElems[ x ][ y ]
if Empty( At( "\line", cTag ) )
cRtf := StrTran( cRtf, cTag, " " )
else
cRtf := StrTran( cRtf, cTag, CRLF )
endif
else
endif
Next y
else
cTag := aElems[ x ]
if Empty( At( "\line", cTag ) )
cRtf := StrTran( cRtf, cTag, " " )
else
cRtf := StrTran( cRtf, cTag, CRLF )
endif
endif
Next x
Next
endif
Return cRtf
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Re: How to obtain plain text from a RTF control?
hi,
what if you "select" hole RTF and copy into Clipboard and paste back to "Memoedit" (TMultiGet ? )
what if you "select" hole RTF and copy into Clipboard and paste back to "Memoedit" (TMultiGet ? )
greeting,
Jimmy
Jimmy
Re: How to obtain plain text from a RTF control?
Yes, that is another possibility that I was studying
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Re: How to obtain plain text from a RTF control?
Could we access DATA oRtf.text mentioned here? https://stackoverflow.com/questions/595 ... n-rtf-text
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
BCC5.82/BCC7.3
xHarbour/Harbour
Re: How to obtain plain text from a RTF control?
Thanks Cristobal.
I have tested this function and it is able to meet my need.
I just added a line at the end that strip out chr(0) because for some reason some of the RTF text that I used for testing has that embedded in it, causing empty() to always returns .f. eventhough there is nothing that can be seen.
I have tested this function and it is able to meet my need.
I just added a line at the end that strip out chr(0) because for some reason some of the RTF text that I used for testing has that embedded in it, causing empty() to always returns .f. eventhough there is nothing that can be seen.
cnavarro wrote:This is a function that does a good conversion (still not perfect though)
Code: Select all | Expand
#include "Fivewin.ch" Function Main() ? SaveRtfAsTxt( ".\Tutorial2.rtf" ) Return nil //----------------------------------------------------------------------------// Function SaveRtfAsTxt( cFile ) local aTags local cTag local cRtf local aElems local x local y if File( cFile ) cRtf := hb_MemoRead( cFile ) aTags := hb_RegExAll( "{\*?\\.+(;})|\s?\\[A-Za-z0-9]+|\s?{\s?\\[A-Za-z0-9]+\s?|\s?}\s?", cRtf ) XBrowse( aTags ) For each aElems in aTags For x = 1 to Len( aElems ) if Valtype( aElems[ x ] ) = "A" For y = 1 to Len( aElems[ x ] ) if Valtype( aElems[ x ][ y ] ) = "C" cTag := aElems[ x ][ y ] if Empty( At( "\line", cTag ) ) cRtf := StrTran( cRtf, cTag, " " ) else cRtf := StrTran( cRtf, cTag, CRLF ) endif else endif Next y else cTag := aElems[ x ] if Empty( At( "\line", cTag ) ) cRtf := StrTran( cRtf, cTag, " " ) else cRtf := StrTran( cRtf, cTag, CRLF ) endif endif Next x Next endif Return cRtf
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
BCC5.82/BCC7.3
xHarbour/Harbour
- Antonio Linares
- Site Admin
- Posts: 42520
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 75 times
- Contact:
Re: How to obtain plain text from a RTF control?
Have you tried using oRichEdit:GetText() ?hua wrote:Which DATA or METHOD in a rtf class should be used to get the content in plain text (without changing the actual content)?
TIA