Paste html, best method? Demo?

General TRichView support forum. Please post your questions here
Post Reply
Lucian
Posts: 56
Joined: Fri Aug 01, 2014 9:52 am

Paste html, best method? Demo?

Post by Lucian »

Hi Sergey,

What's the best approach to insert copied html (hyperlinks, images, tables, etc) from a web-page into a TRichView. In some other thread you mentioned "TRvHtmlImporter or TrvHtmlViewImporter (better)"? Any good demo?

Thx,
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Both importers have LoadFromClipboard method. They replace existing content of TRichView and load HTML from the Clipboard.
If you need a normal pasting operation, then use OnPaste event: load HTML from the Clipboard to a hidden TRichView, save it to TMemoryStream (SaveRVFToStream) and insert in the target editor (InsertRVFFromStreamEd).

In RichViewActions, there is a function PasteHTML (RichViewActions.pas) that does this work. It can work both with TRvHtmlImporter and TrvHtmlViewImporter, depending on the compiler defines.
If you do not use RichViewActions, you can create HTML pasting procedure basing on this procedure.
If you use RichViewActions, it pastes it automatically, if you compile them with support of importers, see
http://www.trichview.com/help-actions/r ... porter.htm
http://www.trichview.com/help-actions/r ... porter.htm

As it was noticed, TrvHtmlViewImporter provides better results.
Lucian
Posts: 56
Joined: Fri Aug 01, 2014 9:52 am

Post by Lucian »

Hi Sergey,

LoadFromClipboard methods doesnt't copy any images. I understand why ... I was hoping that someone already did the connection with Indy (for example) and succeeded in having a "true" clipboard copy :-(

In any case, we decided so far to ignore images.
Life is harsh :-)

Thx
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Yes, usually links to images are on remote servers, and you need to download them.
If RichViewActions are compiled with the support of Indy or CleverComponents:
http://www.trichview.com/help-actions/indy.htm
http://www.trichview.com/help-actions/c ... onents.htm
they do it automatically.
Otherwise, you need to implement downloading yourself, in TRichView.OnImportPicture event.
An example of implementation can be found in RichViewActions.pas, TRVAControlPanel.DoImportPicture method.
It uses FDownloadedPictures: TStringList to avoid downloading the same picture multiple times when importing the same HTML .
It saves downloaded pictures in temporal files, because VCL does not have a public method returning a graphic class by file extension, so we need a workaround with files.
Post Reply