Page 1 of 1

Converting HTML to RTF

Posted: Fri Aug 09, 2013 6:35 am
by dmitrys
I cannot seem to convert an HTML with a link to RTF – the link color is exported but not the actual link.

I used TRvHtmlImporter2.LoadHtml / TRichView.SaveRTFToStream

I used the following HTML:
<html><body>This activity was created by <b><a href="http://www.dimastr.com/redemption">Rede ... ody></html>

Which generated the RTF below.
Did I forget to set a particular flag?

Thank you!

{\rtf1\ansi\ansicpg0\uc1\deff0\deflang0\deflangfe0{\fonttbl{\f0\fnil Arial;}{\f1\fnil Times New Roman;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}
\pard\fi0\li0\ql\ri0\sb0\sa0\itap0 \plain \f0\fs20 This activity was created by \plain \f0\ul\fs20\cf2 Redemption\par}

Posted: Fri Aug 09, 2013 7:42 am
by Sergey Tkachenko
What version of TRichView? In earlier versions, to import and export hyperlinks, you needed to process OnReadHyperlink and OnWriteHyperlink events.
In the new version, it is not necessary, links are imported and exported by default.

By the way, how do you import HTML?

Posted: Fri Aug 09, 2013 1:49 pm
by dmitrys
I am using 13.6.3. To load HTML,I am using TRvHtmlImporter2.LoadHtml.
What do OnReadHyperlink and OnWriteHyperlink event haandlers need to do?

Thank you!

Posted: Fri Aug 09, 2013 4:19 pm
by Sergey Tkachenko
Consider upgrading to the newest version, free updates did not expire for you order. I opened protected forums for your account, you can find new version in the protected "Announcements" forum.

If you do not want to upgrade now, a typical processing of these events is:
- OnReadHyperlink: storing the link target in the item tag
- OnWriteHyperlink: getting the link target from the item tag.

Code: Select all

procedure TMyForm.MyRichViewReadHyperlink(Sender: TCustomRichView; 
  const Target, Extras: String; DocFormat: TRVLoadFormat;
  var StyleNo: Integer; var ItemTag: TRVTag; 
  var ItemName: TRVRawByteString);
begin
  ItemTag := Target;
end;

procedure TMyForm.MyRichViewWriteHyperlink(
  Sender: TCustomRichView; id: Integer;
  RVData: TCustomRVData; ItemNo: Integer;
  SaveFormat: TRVSaveFormat;
  var Target, Extras: String);
begin
  Target := RVData.GetItemTag(ItemNo);
end;

Posted: Fri Aug 09, 2013 9:24 pm
by dmitrys
That worked perfectly, thank you!