Converting HTML to RTF

General TRichView support forum. Please post your questions here
Post Reply
dmitrys
Posts: 10
Joined: Fri Aug 09, 2013 6:31 am

Converting HTML to RTF

Post 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}
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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?
dmitrys
Posts: 10
Joined: Fri Aug 09, 2013 6:31 am

Post 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!
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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;
dmitrys
Posts: 10
Joined: Fri Aug 09, 2013 6:31 am

Post by dmitrys »

That worked perfectly, thank you!
Post Reply