Some test text!

Loading...
Guides

Creating PDF free text annotations using JavaScript

Here is an example of creating a free text annotation using JavaScript, but creating other types of annotations are similar.

WebViewer(...)
  .then(instance => {
    const { Annotations, annotationManager, documentViewer } = instance.Core;

    documentViewer.addEventListener('documentLoaded', () => {
      const freeText = new Annotations.FreeTextAnnotation();
      freeText.PageNumber = 1;
      freeText.X = 150;
      freeText.Y = 200;
      freeText.Width = 150;
      freeText.Height = 50;
      freeText.setPadding(new Annotations.Rect(0, 0, 0, 0));
      freeText.setContents('My Text');
      freeText.FillColor = new Annotations.Color(0, 255, 255);
      freeText.FontSize = '16pt';

      annotationManager.addAnnotation(freeText, { autoFocus: false });
      annotationManager.redrawAnnotation(freeText);
    })
  })

Get the answers you need: Support