Add text annotation to a document using JavaScript

To add a sticky note (text annotation) to a PDF Document.

JavaScript

1async function main() {
2 const doc = await PDFNet.PDFDoc.createFromURL(filename);
3 const page = await doc.getPage(1);
4
5 // Create the sticky note (Text annotation)
6 const txt = await PDFNet.TextAnnot.create(doc, new PDFNet.Rect(10, 20, 30, 40));
7 await txt.setIcon("UserIcon");
8 await txt.setContents("The quick brown fox ate the lazy mouse.");
9 await txt.setColor(await PDFNet.ColorPt.init(0, 1, 0));
10 await txt.refreshAppearance();
11 await page.annotPushBack(txt);
12}
13PDFNet.runWithCleanup(main);

Add or edit PDF annotations
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
Add Text Annotations in PDF Viewer: JavaScript Library | Apryse documentation