Hi,
Is there a single function for converting RTF text to HTML without using components?, I mean, .... just like WPToolsRTFtoANSI.
Best regards.
Hi,
Is there a single function for converting RTF text to HTML without using components?, I mean, .... just like WPToolsRTFtoANSI.
Best regards.
I think the easisest way is to use the Component - because you can create it dynamic you don't need any visual components
this is a code from my project don't know if it works perfect ;)
type
TWPHTMLExport = class(TWPCustomRTFEdit)
protected
fHTMLImgNr : integer;
fHTMLImgPath : string;
fHTMLName : string;
procedure _PrepareImageforSaving(RTFData: TWPRTFDataCollectionBase; Writer: TWPCustomTextWriter; TextObject: TWPTextObj; var DontSave: Boolean);
public
constructor CreateDynamic;
end;
constructor TWPHTMLExport.CreateDynamic;
begin
Create(nil);
_MakeDynamic;
fHTMLImgNr := 0;
Memo.RTFData._InternOnPrepareImageforSaving := _PrepareImageforSaving;
end;
procedure TWPHTMLExport._PrepareImageforSaving(RTFData: TWPRTFDataCollectionBase; Writer: TWPCustomTextWriter; TextObject: TWPTextObj; var DontSave: Boolean);
var
fileName : string;
begin
TextObject.Source := '';
if TextObject.ObjRef <> nil then begin
TextObject.ObjRef.StreamName := '';
inc(fHTMLImgNr);
fileName := TextObject.ObjRef.SaveToFile(IncludeTrailingPathDelimiter(fHTMLImgPath)+Format(fHTMLName+'_%d', [fHTMLImgNr] ));
TextObject.ObjRef.FileName := ExtractFileName(fileName);
end;
end;
function ConvertToHTMLText(WPText : string; htmlName, imgPfad : string) : string;
var
temp : TWPHTMLExport;
begin
temp := TWPHTMLExport.CreateDynamic;
temp.fHTMLName := htmlName;
temp.fHTMLImgPath := imgPfad;
temp.AsString := WPText;
Result := temp.AsAnsiString('HTML');
temp.Free;
end;
Alles anzeigen
Thank you Andi, I will give it a try.