Internal Hyperlink in RTF documents

General TRichView support forum. Please post your questions here
Post Reply
matteop
Posts: 5
Joined: Fri Oct 05, 2007 10:18 am
Contact:

Internal Hyperlink in RTF documents

Post by matteop »

Hello,
I've searched the forum but I've not found any example matching my question. I've to create run time an RTF document with internal links and I dont know the functions of the TRichView component Ive to call to
- create the link. I think the RTF code maybe like this:

Code: Select all

{\field{\*\fldinst HYPERLINK \\l "_Recording_List" }{\fldrslt \pard\f0\fs20\cf0 Element2}}
- create the anchor where the previous link points, with a code like this (I think):

Code: Select all

{\*\bkmkstart _Recording_List}{\*\bkmkend _Recording_List}Element5
Any suggestion?

Thanks in advance,

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

Post by Sergey Tkachenko »

This feature is much better implemented in the latest version available for registered users, than in the trial version.

1) Bookmarks.
RichView checkpoints are saved in bookmarks. Checkpoint name is used as bookmark name. The trial version can save bookmark. The last version can save and load them.

2) Links to bookmarks.
The last version automatically saves the link "#_Recording_List" as link to "_Recording_List" bookmark (and performs a reverse operation when loading). So standard code for OnReadHyperlink and OnWriteHyperlink is enough:

Code: Select all

procedure TfrmMain.rveReadHyperlink(Sender: TCustomRichView; const Target,
  Extras: String; DocFormat: TRVLoadFormat; var StyleNo, ItemTag: Integer;
  var ItemName: String);
begin
  ItemTag := Integer(StrNew(PChar(Target)));
end;

procedure TfrmMain.rveWriteHyperlink(Sender: TCustomRichView; id: Integer;
  RVData: TCustomRVData; ItemNo: Integer; SaveFormat: TRVSaveFormat;
  var Target, Extras: string);
begin
  Target := PChar(RVData.GetItemTag(ItemNo));
end;
In trial version, you can use OnWriteHyperlink event to add "\l" in Extras when necessary (but, as far as I know, it is not necessary in new versions of MS Word, they should understand "#"-links as well)

Update 2011-Oct-22: Starting from TRichView 13.3, the code must be:

Code: Select all

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

procedure TfrmMain.rveWriteHyperlink(Sender: TCustomRichView; id: Integer; 
  RVData: TCustomRVData; ItemNo: Integer; SaveFormat: TRVSaveFormat; 
  var Target, Extras: string); 
begin 
  Target := RVData.GetItemTag(ItemNo); 
end;
Last edited by Sergey Tkachenko on Sat Oct 22, 2011 6:54 pm, edited 1 time in total.
matteop
Posts: 5
Joined: Fri Oct 05, 2007 10:18 am
Contact:

Post by matteop »

Hi and thanks for the answers!

So, to create the RTF with the hyperlinks (without user input but all in the program's code) I've to add a tag to write the hyperlink and add a bookmark to write the anchor where the hyperlink points, right?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Yes.
matteop
Posts: 5
Joined: Fri Oct 05, 2007 10:18 am
Contact:

Post by matteop »

Sergey Tkachenko wrote:This feature is much better implemented in the latest version available for registered users, than in the trial version.
I'm using a registered 1.9.15 version

Ok, after some experiments I've an almost working code, writing this string:

Code: Select all

{\field{\*\fldinst HYPERLINK "1" \\l}{\fldrslt \plain \f1\ul\fs20\cf11 LINK}}
but when I click on the link it try to open a 1.rtf file, instead with

Code: Select all

{\field{\*\fldinst HYPERLINK \\l "1" }{\fldrslt \plain \f1\ul\fs20\cf11 LINK}}
it would be correct.

I've solved with

Code: Select all

procedure TmainForm.exporteditWriteHyperlink(Sender: TCustomRichView;
  id: Integer; RVData: TCustomRVData; ItemNo: Integer;
  SaveFormat: TRVSaveFormat; var Target, Extras: String);
begin
   Extras := '\l' + '"' + IntToStr((RVData.GetItemTag(ItemNo)))+ '"';
   Target := '';
end;

Thanks!

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

Post by Sergey Tkachenko »

I recommend to upgrade to the newer version.
I can open access to the protected section of this form for you. Send me a private message with e-mail address you used when ordered TRichView.
Usch Wildt
Posts: 20
Joined: Fri Sep 29, 2006 11:30 am

some more explanation?

Post by Usch Wildt »

Hello,

I also need internal references in documents, but I don't understand you explanations in this topic.
I know how to create a Checkpoint, but how can I create a link to this checkpoint? Where and to what do I add the "{\field{...". If I just add it as text, it is just text of course. Does it have to be a tag of some item or how(where/to what do I have to add it?
Could you give a small code example?

Thank you very much!

Usch Wildt
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You do not need to worry about RTF fields, TRichView saves all this stuff automatically.

As for checkpoints, see RichView Items' "Checkpoints" Overview in the help file. In editor, they are inserted with SetCurrentCheckpointInfo. The latest version also has an alternative method InsertCheckpoint.
Checkpoints have names, these names are stored in RTF as bookmark names (checkpoints also have tags, but they are not stored in RTF)
The only difference between checkpoints and RTF bookmarks: checkpoints define the specific position, not a text fragment like bookmark.

As for links, process them just like external links. Just add '#' to the beginning of target. I.e., if checkpoint name = 'abc', link target must be '#abc'. TRichView will save such links correctly both in HTML (no conversion is needed) and RTF (by converting them to links to bookmarks).
The latest version is required for automatic local links conversion and for loading bookmarks from RTF.
Usch Wildt
Posts: 20
Joined: Fri Sep 29, 2006 11:30 am

reference with dynamic text?

Post by Usch Wildt »

Hi,

thank you for your quick answer!
Unfortunately I think I need bookmarks on a text fragment, noit only a position, because I would like to make dynamic text references like "see chapter xxx", where xxx is the text of the chapter title, and the text "see chapter xxx" changes to "see chapter yyy", when the chapter title is changed from xxx to yyy.
And - if possible - all this should survive an export to Word; so I would like to have fields like {REF _Ref123 \r \h } and {REF _Ref123 \h } in Word.
Is that possible?

Thanks a lot!

Usch Wildt
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Unfortunately, references are not supported yet.
You can insert RTF code in the specific place of document in 2 ways:
1) Insert text with rvteoRTFCode in Options of text style (and protected, so that user cannot edit it)
2) Insert some component, and use OnSaveComponentToFile event.
Post Reply