Add link annotation to a document using JavaScript

To add a hyperlink or intra-document link annotation to a PDF Document page.

JavaScript

1async function main() {
2 const doc = await PDFNet.PDFDoc.createFromURL(filename);
3 const firstPage = await doc.getPage(1);
4
5 // Create a hyperlink
6 const createURIAction = await PDFNet.Action.createURI(doc, 'http://www.apryse.com');
7 const linkRect = new PDFNet.Rect(85, 570, 503, 524);
8 const hyperlink = await PDFNet.LinkAnnot.create(doc, linkRect);
9 await hyperlink.setAction(createURIAction);
10 await hyperlink.refreshAppearance();
11 await firstPage.annotPushBack(hyperlink);
12
13 // Create an intra-document link
14 const page3 = await doc.getPage(3);
15 const gotoPage3 = await PDFNet.Action.createGoto(await PDFNet.Destination.createFitH(page3, 0));
16 const link = await PDFNet.LinkAnnot.create(doc, (new PDFNet.Rect(85, 458, 503, 502)));
17 await link.setAction(gotoPage3);
18 await link.refreshAppearance();
19 await firstPage.annotPushBack(link);
20}
21PDFNet.runWithCleanup(main);

Add or edit PDF annotations sample
Full code sample which shows how to add or edit PDF annotations (e.g. hyperlink, intra-document link, stamp, rubber stamp, file attachment, sound, text, free-text, line, circle, square, polygon, polyline, highlight, squiggly, caret, and ink).

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales