Back to Blog

    Developer Blog

    Add links to a PDF programmatically

    Foxit Quick PDF Library

    Adding links to PDF files is very straight forward. A link in a PDF is actually an annotation and is placed on top of the content that you wish to link. These hotspot links can be added using the following functions:

    Read more about annotations and hotspot links.

    An example of how to use the AddLinkTo* functions is shown below.

    /* Add a link to a specific page in an external PDF */
    
    // Set the origin for the co-ordinates to be the
    // top left corner of the page.
    
    DPL.SetOrigin(1);
    
    // Adding a link to a page in an external PDF
    // is easy using the AddLinkToFile function.
    
    DPL.AddLinkToFile(200, 100, 60, 20, "Moby_Dick_NT.pdf", 22, 200, 1, 1);
    
    // Hyperlinks and text are two separate
    // elements in a PDF, so we'll draw some
    // text now so that you know where the
    // hyperlink is located on the page.
    
    DPL.DrawText(205, 114, "Click me!");
    
    // When the Foxit Quick PDF Library object is initiated a blank document
    // is created and selected in memory by default. So
    // all we need to do now is save the document to
    // the local hard disk to see the changes that we've made.
    
    DPL.SaveToFile("link_to_another_doc.pdf");
    

    This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.