PDFtoolkit VCL
Edit, enhance, secure, merge, split, view, print PDF and AcroForms documents
Delphi C++Builder

How To Add Hyperlinks To Images In A PDF Document

"I have a list of URLs that need to be added to a set of images that repeat in every page of a PDF document."
By Mohammed Najeemudheen & Shine Babu

When images are used as hyperlinks, it adds a small but significant touch of interactivity to PDF documents. In this tip, we will show you how to add a set of URLs to images in a PDF document.

Here, we assume that each page in the document have the same set of images and that we need to add the URLs in the order we find the images in each page.

The code for this is pretty simple. First, we put the URLs (URIs) in a list. Then, we load each page in the document. Next, we identify where the images are located on the pages. We then create a link annotation for each image and set the annotation's rectangle to the dimensions of the image. Finally, each link annotation is set to a URL that corresponds to the order of the image in the page.

  LinkAnnot : TgtPDFLinkAnnotation;
  URI : TgtPDFURIAction;
  LImageList : TgtPDFPageElementList;
  LStringLinks : TStringList;
  StrLink : String;
  LI,LJ,LK : Integer;
  LLeft, LRight, LBottom, LTop,LWidth, LHeight: Double;
  LStringLinks := TStringList.Create;
  PDFDoc.OpenAfterSave := True;
  // Creates a link annotation object
  LinkAnnot := TgtPDFLinkAnnotation.Create;
  LinkAnnot.Contents := 'PDFtoolkit';

  // Creates a URI object
  URI := TgtPDFURIAction.Create ;

  // Sets the properties of the link annotation
  LinkAnnot.BackgroundColor := clBlue;
  LinkAnnot.AnnotTitle := 'LinkAnnotion';
  LinkAnnot.Name := 'Link1';
  LinkAnnot.BorderWidth := 0;

  // Creates a list of URIs

 // for each page in the document ...
 for LJ:= 1 to PDFDoc.PageCount do
    // Creates a list of image items in a given page
    LImageList := 
    LK := 0;
    // for each image in the list ...
    for LI:= 0 to LImageList.Count - 1 do
      if LK < LStringLinks.Count then
        // Sets the URI property of the link annotation 
        // action to a corresponding URL from the list
        URI.URI := LStringLinks[LK];
        LinkAnnot.Action :=  URI;

        // Obtains the width and height of image
        LWidth := TgtPDFImageElement(
        LHeight := TgtPDFImageElement(

        LLeft := LImageList.Items[LI].XCordOrigin;
        LTop := LImageList.Items[LI].YCordOrigin + LHeight ;
        LRight := LImageList.Items[LI].XCordOrigin +LWidth ;
        LBottom := LImageList.Items[LI].YCordOrigin;

        // Specifies the annotation rectangle
        LinkAnnot.SetBounds(LLeft, LTop, LRight, LBottom);

        // Adds the link annotation on the image
          if LK = LStringLinks.Count then
            LK := 0;
  // Saves the PDF document


Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.


A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
Gnostice Document Studio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
Gnostice Document Studio Java

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2024 Gnostice Information Technologies Private Limited. All rights reserved.