Load+Save HTML with TWPRichText and preserve embedded images

  • I want to use a TWPRichText control as an email client editor.

    How do I load an HTML file (with embedded images) into a TWPRichText control so that the images are imported as well? I tried:

    TWPRichText.LoadFromFile('c:\\google.htm', False, 'HTML');

    but this seems to ignore IMG tags.


    Also, how do I save the edited RTF data from the TWPRichText control as an HTML file, along with all referenced embedded IMG tags?

    Any help would be appreciated.

    • Offizieller Beitrag

    To learn how to save HTML emails please see article
    http://wpcubed.com/forum/viewtopic.php?p=3287#3287

    How to load HTML and fetch the images:

    WPTools will not create a connection to the internet to download images. It will create the events OnRequestHTTPImage for each IMG it finds and you can use Indy or Synapse to download the image from the web.

    The event OnRequestHTTPImage should be used to load the images when the HTML reader comes to the IMG tag. That also works with RTF files which have linked images!

    The key line in the event handler is
    TextObject.LoadObjFromStream(URL,stream);

    Example - using Indy9:

    Code
    procedure TForm1.WPRichText1RequestHTTPImage(RTFData: TWPRTFDataCollection;  Reader: TWPCustomTextReader; const LoadPath, URL: String;  TextObject: TWPTextObj; var Ok: Boolean);var stream : TMemoryStream;    loadurl : string;begin  if pos('http:',lowercase(URL))>0 then      loadurl := URL  else loadurl := LoadPath + URL;  stream := TMemoryStream.Create;  try    Panel2.Caption := URL;    try      Application.ProcessMessages;      IdHTTP1.Get(loadurl,stream);    except      on e : Exception do Panel2.Caption := URL + '-->' + e.Message;    end;    if stream.Size>0 then    try       TextObject.LoadObjFromStream(URL,stream);    except       on e : Exception do Panel2.Caption := URL + '-->' + e.Message;    end;    ok := TRUE;    if ok then Panel2.Caption := '';    Application.ProcessMessages;  finally    stream.Free;  end;end;

    I was not so happy with the loads of exceptions Indy produced and so didn't persue this further. But the handler itself is correct.

    BTW - the CSS includes can be loaded using in OnRequestHTTPString - this was the code to do it:

    Zitat

    Also, how do I save the edited RTF data from the TWPRichText control as an HTML file, along with all referenced embedded IMG tags?

  • When I use RtfText.AsString to 'load' a html text, the event RequestHTTPImage is not triggered. Is it possible to somehow trigger this event without having to save as html first?

    Kind regards,
    Jeroen