Some test text!

Search
Hamburger Icon

Web / Guides

Edit annotation style properties using JavaScript

Make sure you have Full API enabled in WebViewer.

To set an annotation style property such as color, interior color, border style, padding, etc to an annotation.

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

  const circle = await PDFNet.CircleAnnot.create(
    doc,
    new PDFNet.Rect(100, 100, 200, 200)
  );
  await circle.setColor(await PDFNet.ColorPt.init(0, 1, 0), 3);
  await circle.setInteriorColor(await PDFNet.ColorPt.init(0, 0, 1), 3);
  const dash = [2, 4];
  await circle.setBorderStyle(
    await PDFNet.AnnotBorderStyle.createWithDashPattern(
      PDFNet.AnnotBorderStyle.Style.e_dashed,
      3,
      0,
      0,
      dash
    )
  );
  await circle.setPadding(new PDFNet.Rect(2, 2, 2, 2));
  await circle.refreshAppearance();
  await page.annotPushBack(circle);
}
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).

Get the answers you need: Chat with us