Pictures from URL

General TRichView support forum. Please post your questions here
Post Reply
Posts: 4
Joined: Thu Aug 02, 2018 1:50 pm

Pictures from URL

Post by SergJP » Fri Nov 30, 2018 9:03 am

I import HTML text of email from database using TRVHTMLViewImporter and THtmlViewer.
When the letter contains pictures with src = "http://some site" TRVHTMLViewImporter adds a prefix - path of executable file.
The code is:

Code: Select all

		RVHTMLViewImporter = new TRVHTMLViewImporter(Owner);
		RVHTMLViewImporter->HTMLViewer = HTMLViewer;
		RVHTMLViewImporter->AutoHyperlinks = false;
               RVHTMLViewImporter->ImgSrcToImageName = true;
		TMemoryStream *stream = new TMemoryStream();
		HTMLViewer->LoadFromStream(stream, path,HTMLType);
		RVHTMLViewImporter->ImportHtmlViewer(HTMLViewer, rvMail, path); // Here is error: Cannot open file "c:\work\...Win32\Debug\http:\www.some site\image.jpg"
rvMail is TRichViewEdit where text will imported to.
I tried to switch this properties
RVHTMLViewImporter->AutoHyperlinks = false;
RVHTMLViewImporter->ImgSrcToImageName = true;
but is no effect.

In event handlers
HTMLViewer->OnImageRequest = HtmlViewer1ImageRequest;
HTMLViewer->OnImageRequested = HtmlViewer1ImageRequested;
HTMLViewer->OnFilenameExpanded = HtmlViewer1FilenameExpanded;
all URLs are correct.
Where and who adds a prefix "c:\work...\" to them I have no idea.
What should I do?

Sergey Tkachenko
Site Admin
Posts: 14764
Joined: Sat Aug 27, 2005 10:28 am

Re: Pictures from URL

Post by Sergey Tkachenko » Fri Nov 30, 2018 6:46 pm

I believe it's not TRVHTMLViewImporter adds this prefix. This prefix is added later by Delphi when displaying this error message.
In any case, TRVHTMLViewImporter ignores pictures inside THTMLViewer and tries to load them itself. So the result of THTMLViewer's image requesting events is not used.
And, by default, TRVHTMLViewImporter can load only local images. HTTP and HTTPS images must be downloaded.

If you use RichViewActions, you can assign RVHTMLViewImporter to RVAControlPanel->HTMLComponent, and RVIndyDownloadInterface to RVAControlPanel->DownloadInterface, and pictures will be downloaded using Indy.

If you do not use RichViewActions, you need to process TRichViewEdit->OnImportPicture event and download the picture, if the image location starts from HTTP or HTTPS, for example, using TIdHttp component.

Post Reply