Add link annotations

<< Click to Display Table of Contents >>

Navigation:  Tasks > Internal Actions >

Add link annotations

Link annotations can be created using the DrawAnnotAny action by specifying the PDF properties which should be created in the PDF file.

 

Example - add a link to a webpage

 

procedure TForm1.AddWeblink1Click(Sender: TObject);

var s : string;

begin

  s := 'http://www.wpcubed.com';

  if (pdf<>niland InputQuery('Add weblink', 'URL', s) then

  begin

    pdf.CommandStrEx( COMPDF_ACTION,

        'DrawAnnotAny="type=Link","prp.i.F=4","prp.a.Border=0 0 0",' +

        '"prp.A.n.Type=Action","prp.A.n.S=URI","prp.A.s.URI=' + s + '"', 0);

  end;

end;

 

Example - add a link to page

   

In this example the page is provided as number, rage 1..pagecount

 

procedure TForm1.Addlinktopage1Click(Sender: TObject);

var s : string;

    i : Integer;

begin

  s := IntToStr(pdf.Page);

  if (pdf<>niland InputQuery('Add link to page', 'Nr', s) then

  begin

    i := StrToInt(s);

    if (i<1) or (i>pdf.PageCount) then

         ShowMessage('Pagenumber not valid')

    else

    begin

     // this code uses the page number directly.

       pdf.CommandStrEx( COMPDF_ACTION,

        'DrawAnnotAny="type=Link","prp.i.F=4","prp.a.Border=0 0 0",' +

        '"prp.r.Dest=[#' + IntToStr(i) + ' /XYZ 0 500]"', 0);

    end;

  end;

end;

 

In this example the page number is stored as ID. The command COMPDF_GetGetPageObjectID (226) is used to retrieve the page id.

Note: The ID is enclosed in { }.

 

procedure TForm1.Addlinktopage1Click(Sender: TObject);

var s : string;

    i : Integer;

begin

  s := IntToStr(pdf.Page);

  if (pdf<>niland InputQuery('Add link to page', 'Nr', s) then

  begin

    i := StrToInt(s);

    if (i<1) or (i>pdf.PageCount) then

         ShowMessage('Pagenumber not valid')

    else

    begin

     // In the code below we use the page identifier

       pdf.CommandStrEx( COMPDF_ACTION,

        'DrawAnnotAny="type=Link","prp.a.Border=0 0 0","prp.i.F=4","prp.r.Dest=[#' +

            pdf.CommandGetStr(COMPDF_GetGetPageObjectID, '', i-1)

           + ' /XYZ 0 500]"', 0);

 

    end;

  end;

end;