Method SetLinkArea

Top  Previous  Next

This procedure defines a hotlink in the PDF file. The X and Y values are the expected as twips coordinates relative to the top-left corner of the current page. (You have to add the top margin and left margin)

 

Parameters:

 

const BookMarkName : string        

This is the name of the book mark which should be located when the user clicks on the hotspot.

 

If the name starts with http:// which is a web link, if it starts with Launch:// it starts a file.

 

R : TRect        

This is the rectangle position on the current page which should be marked as hotlink. Please note that the WPTools export engine TWPDFExport already automatically deals with hyperlinks. (A hyperlink is defined as text with the style afsHyperlink in wptools) followed by some invisible text which is the book mark name.

 

Example

a) Create a link which opens the file 'c:\test.htm':

 

WPPDFPrinter1.SetLinkArea('Launch://c:\test.htm',

     Rect(10,10,100,100));

 

b)Create a link which opens the file 'c:\test.pdf':

 

WPPDFPrinter1.SetLinkArea('GoToR://c:\test.pdf',

     Rect(10,10,100,100));

 

use this string parameter to open the PDF at page #3:

 

'GoToR://c:\test.pdf#2' // First page = 0

 

and this to open the PDF at named destination "ORANGE" :

 

'GoToR://c:\test.pdf#ORANGE'

 

 

c) Create link areas for whole lines which have a colored background. (Can be modified to create links in a table of contents)

 

procedure        TForm1.WPPDFExport1AfterPrintPage(Sender: TObject; Number,

 FromPos, Length: Integer);

var

 r : TRect;

 toppos : Integer;

begin

 WPPDFExport1.Source.CPPosition := FromPos;

 toppos := WPPDFExport1.Source.Memo.active_line^.y_start;

while Length>0 do

begin

    //        Only if        at start of a line process the following code

    if WPPDFExport1.Source.CPColNr =0 then

    begin

 // we check if paragraph is colored. We        could also

 // check the paragraph id or any other property.

 if WPPDFExport1.Source.Memo.active_paragraph^.color<>0 then

 begin

  // Calculate the rectangle for the current line

   WPPDFExport1.Source.GetLinRect(

                 WPPDFExport1.Source.Memo.active_paragraph,

     WPPDFExport1.Source.Memo.active_line, r);

 

          // Move the rectange according to the defined margins

   dec(r.Top, toppos-WPPDFExport1.Source.Header.TopMargin);

   dec(r.Bottom,

                toppos-WPPDFExport1.Source.Header.TopMargin);

   inc(r.Left, WPPDFExport1.Source.Header.LeftMargin);

   inc(r.Right, WPPDFExport1.Source.Header.LeftMargin);

   WPPDFExport1.SetLinkArea('LINK',r);

 end;

    end;

    Dec(Length);

    if not WPPDFExport1.Source.CPMoveNext then break;

end;

end;