Creating link annotations with text

Q: I created a link annotation but it is empty. How can I set the text?

A: For flexibility, link annotations don’t actually include the text that is shown, but they should be overlaid on top of existing annotations to perform specific actions when clicked (link annotations themselves are invisible).

If you just want to create a regular text link, you should create a link annotation that has the same bounding box as an existing text annotation you created. See an example below:

Copy
1
2
3
4
5
6
7
8
9
const uriAction = new PSPDFKit.Actions.URIAction({ uri: "https://pspdfkit.com" })

const linkAnnotation = new PSPDFKit.Annotations.LinkAnnotation({
  pageIndex: existingTextAnnotation.pageIndex,
  boundingBox: existingTextAnnotation.boundingBox,
  action: uriAction,
})

instance.createAnnotation(linkAnnotation)

Link annotations can also be used for other annotation and action types. Check out the API docs for more information.