Page 1 of 1

Pictures from URL

Posted: Fri Nov 30, 2018 9:03 am
by SergJP
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();
		((TBlobField*)qPost->FieldByName("htmltext"))->SaveToStream(stream);
		stream->Seek(0,0);
		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?

Re: Pictures from URL

Posted: Fri Nov 30, 2018 6:46 pm
by Sergey Tkachenko
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.