Some test text!

Search
Hamburger Icon

Web / Guides

Add link annotation to a document using JavaScript

Make sure you have Full API enabled in WebViewer.

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

async function main() {
  const doc = await PDFNet.PDFDoc.createFromURL(filename);
  const firstPage = await doc.getPage(1);

  // Create a hyperlink
  const createURIAction = await PDFNet.Action.createURI(doc, 'http://www.apryse.com');
  const linkRect = new PDFNet.Rect(85, 570, 503, 524);
  const hyperlink = await PDFNet.LinkAnnot.create(doc, linkRect);
  await hyperlink.setAction(createURIAction);
  await hyperlink.refreshAppearance();
  await firstPage.annotPushBack(hyperlink);

  // Create an intra-document link
  const page3 = await doc.getPage(3);
  const gotoPage3 = await PDFNet.Action.createGoto(await PDFNet.Destination.createFitH(page3, 0));
  const link = await PDFNet.LinkAnnot.create(doc, (new PDFNet.Rect(85, 458, 503, 502)));
  await link.setAction(gotoPage3);
  await link.refreshAppearance();
  await firstPage.annotPushBack(link);
}
PDFNet.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).

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales