Tagging Links

This guide demonstrates how to create accessible links in PDF documents following best practices for PDF/UA compliance using UniPDF.

Before you begin

You should get your API key from your UniCloud account.

If this is your first time using UniPDF SDK, follow this guide to set up a local development environment.

Clone the project repository

In your terminal, clone the examples repository. It contains the Go code we will be using for this guide.

git clone https://github.com/unidoc/unipdf-examples.git

Navigate to the accessibility folder in the unipdf-examples directory.

cd unipdf-examples/accessibility

How it works

The following example code shows how to create different types of accessible links.

Code Explanation

The code begins by initializing the metered license API key in the init function (lines 21-28). A StructTreeRoot and a base KDictionary of type Document are created (lines 41-47) to form the document’s structure tree. The example then demonstrates creating various types of accessible links.

First, a link with descriptive text (“Download PDF Specification”) is created (lines 61-71). Since the text itself is descriptive, no AltText is needed, but a Tooltip is set to the URL. The AddExternalLinkWithTag method is used to add the link and automatically generate the corresponding structure element. Next, a link with generic text (“Click here”) is created (lines 79-91). In this case, AltText is set to “Download PDF Specification” to provide necessary context for screen readers. The example also shows how to create an email link (mailto:) with a descriptive tooltip (“Send email to…”) (lines 94-106) and an internal link to another page, where the tooltip explains the destination (lines 109-121).

Run the code

Run this command to generate the PDF with accessible links.

go run pdf_tag_link_annot.go

Sample output

The output file will contain links that are properly tagged and have appropriate alternate text and tooltips.

Sample Output

Got any Questions?

We're here to help you.