BerndGabriel / HtmlViewer

The well-known Delphi/Lazarus HtmlViewer/FrameViewer
Other
395 stars 147 forks source link

Images can not be imported into a richedit #324

Closed trichter2 closed 1 year ago

trichter2 commented 1 year ago

Hello, again HTMLViewer-Team, I try to extract the body of an outlook appointment into a richedit. Using redemption I get the HTML body of the appointment. To import the body into the richedit I use the following lines of code: image The text, fonts, and links are displayed perfectly but the images are not. It seems like they can not be loaded. They are displayed with a big red X. Is there anything I can do to display the images? If I open the HTML file everything is fine: image

Best regards Tom

BerndGabriel commented 1 year ago

Hi Tom, could you please post or email an example file/text?

If the image is not a link to a local file system or an embedded base64 image, you can use THtmlViewer.OnImageRequest to provide a TStream with the image. For downloading from the internet you may use Indy or ICS controls. See FrameBrowzerDemoIcs resp FrameBrowzerDemoId10 for details.

trichter2 commented 1 year ago

Hi Bernd, attached you can find a zip file containing an ics file. This file can be imported into Outlook and should be an appointment with the text displayed above.

Test Calendaritem.zip

BerndGabriel commented 1 year ago

Tom, in your application you must implement THtmlViewer.OnImageRequest(Sender: TObject; const SRC: string; var Stream: TStream);

In your example it will be called with SRC = 'cid:image002.jpg@01D8CE82.78A095D0' and Stream = nil.

Your implementation must provide Stream for sources with scheme 'cid:'.

In 'Test Calendaritem-zip' is no image. It should be part of the surrounding MIME tree. Something like

Content-Type: image/jpeg;
Content-ID: <image002.jpg@01D8CE82.78A095D0>
Content-Transfer-Encoding: ...

If OnImageRequest exits with Stream still = nil, THtmlViewer tries to load that source from a the local file system, which will fail.

Without external support THtmlViewer can load files from a local file system, base64 encoded inline images and images from resources (scheme 'res:').

Most probably encoding of your image2.jpg will be base64. See function GetTheBase64(Name: ThString) in HTMLSubs.pas how to convert base64 to a stream.

trichter2 commented 1 year ago

Hello, again Bernd, first of all, thank you for your help. Everything works fine now. Nevertheless, I have gotten some issues importing the HTMLViewer to the HTMLViewImporter. To solve this I have implemented the OnImportPicture event from the richedit. In this event, I load the graphic for the image manually.