AnnoAPI

Updated at:

AnnoAPI is the WebOffice JS-SDK object that provides the annotation methods of the active PDF document. Use the AnnoAPI methods to select annotations, apply highlight, strikethrough, and underline markup, draw with pen tools, and add comments, annotation bubbles, and stamps.

Syntax conventions

In the syntax of the AnnoAPI property and of every AnnoAPI method in this topic, expression is an Application object that represents the document type.

Each example in this topic waits for instance.ready(), obtains the Application object from instance.Application, and then reaches the annotation methods through app.ActivePDF.AnnoAPI.

Obtain the current AnnoAPI object

The ActivePDF.AnnoAPI property returns the current AnnoAPI object. Obtain this object before you call any annotation method.

Syntax

expression.ActivePDF.AnnoAPI

Example

async function example() {
  await instance.ready();

  const app = instance.Application;
  // Obtain the current AnnoAPI object.
  const AnnoAPI = await app.ActivePDF.AnnoAPI;
}

Methods at a glance

The following table lists the AnnoAPI methods by task. Version and platform requirements differ by method, and each method section states the requirement that applies to it.

Task groupMethodDescription
SelectionSelectAnno()Selects an annotation on a specified page.
SelectionClearAnnoSelection()Clears the annotation selection.
SelectionGetAnnoSelection()Retrieves the selected annotations.
SelectionCopyAnnoSelection()Copies the selected annotation.
Text markupSetSelectionAnno()Applies a highlight, strikethrough, or underline annotation to the selection.
Text markupSetAnnoMode()Sets the highlight, strikethrough, or underline annotation mode.
Text markupExitAnnoMode()Exits the annotation mode.
Annotation appearanceSetAnnoStyleBySelection()Sets the bubble style of the selected annotation.
Annotation appearanceSetAnnoLineWidthBySelection()Sets the line width of the selected annotation.
Annotation appearanceSetAnnoColorBySelection()Sets the color of the selected annotation.
Pen and eraserSetInkMode()Sets the pen mode, including the pen type, line width, and color.
Pen and eraserExitInkMode()Exits the pen mode.
Pen and eraserSwitchEraser()Enables or disables the eraser mode.
Comment and stampAddTextAnnoComment()Adds a comment to an annotation.
Comment and stampAddTextData()Adds an annotation bubble at a specified position.
Comment and stampInsertAnnoPic()Inserts a stamp annotation.

Selection methods

The following AnnoAPI methods manage the annotation selection of the active PDF document.

AnnoAPI.SelectAnno()

Selects an annotation on a specified page.

Important

This feature is supported only in JS-SDK V1.1.19 and later.

Syntax

expression.AnnoAPI.SelectAnno({PageIndex, Id})

Parameters

PropertyData typeRequiredDescription
PageIndexNumberYesThe page number where the annotation is located. Page numbers start from 1.
IdStringYesThe annotation ID.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Select an annotation.
  await app.ActivePDF.AnnoAPI.SelectAnno({PageIndex:1, Id: '{8c3300cf-ec08-4350-aab3-2f42c480d92e}'});
}

AnnoAPI.ClearAnnoSelection()

Clears the annotation selection.

Important

This feature is supported only in JS-SDK V1.1.19 and later.

Syntax

expression.AnnoAPI.ClearAnnoSelection()

Parameters

None.

Example

async function example() {
  await instance.ready();
  const app = instance.Application;
  // Clear the annotation selection.
  await app.ActivePDF.AnnoAPI.ClearAnnoSelection();
}

AnnoAPI.GetAnnoSelection()

Retrieves the selected annotations.

Important

This feature is supported only in JS-SDK V1.1.19 and later.

Syntax

expression.AnnoAPI.GetAnnoSelection()

Parameters

None.

Return value

FieldData typeDescription
resultArrayAn array of annotation objects.

Each annotation object in result contains the following fields:

FieldData typeDescription
typeStringThe annotation type.
idStringThe annotation ID.
pageIndexNumberThe page number of the page on which the annotation is located. Page numbers start from 0.
rectObjectThe position information of the annotation.
Note

In the returned annotation object, pageIndex starts from 0. The PageIndex parameter of SelectAnno() and AddTextAnnoComment() starts from 1.

Example

async function example() {
  await instance.ready();
  const app = instance.Application;
  // Retrieve the selected annotations.
  await app.ActivePDF.AnnoAPI.GetAnnoSelection();
}

AnnoAPI.CopyAnnoSelection()

Copies the selected annotation.

Important

This feature is supported only in JS-SDK V1.1.19 and later.

Syntax

expression.AnnoAPI.CopyAnnoSelection()

Parameters

None.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Copy the text of the selected annotation.
  await app.ActivePDF.AnnoAPI.CopyAnnoSelection();

}

Text markup methods

The AnnoAPI object provides two ways to add a highlight, strikethrough, or underline annotation to a PDF document:

  • Annotate the current selection — SetSelectionAnno() applies the annotation to the selection.

  • Annotate in a mode — SetAnnoMode() sets the annotation mode, and ExitAnnoMode() exits it.

AnnoAPI.SetSelectionAnno()

Applies an annotation (highlight, strikethrough, or underline) to the selection.

Important

This feature is supported only in JS-SDK V1.1.19 and later and is available only on PC.

Syntax

expression.AnnoAPI.SetSelectionAnno({type, color})

Parameters

PropertyData typeRequiredDescription
typeEnumYesThe annotation type. For more information, see Enum.AnnoType.
colorStringNoThe color in RGB or RGBA format.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Apply a highlight to the selection.
  await app.ActivePDF.AnnoAPI.SetSelectionAnno({type: app.Enum.AnnoType.Highlight, color: 'rgba(14,14,14,1)'});

}

AnnoAPI.SetAnnoMode()

Sets the annotation mode (highlight, strikethrough, or underline). To exit the mode, call ExitAnnoMode().

Important

This feature is supported only in JS-SDK V1.1.19 and later and is available only on PC.

Syntax

expression.AnnoAPI.SetAnnoMode({type, color})

Parameters

PropertyData typeRequiredDescription
typeEnumYesThe annotation type. For more information, see Enum.AnnoType.
colorStringNoThe color in RGB or RGBA format.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Set the highlight mode.
  await app.ActivePDF.AnnoAPI.SetAnnoMode({type: app.Enum.AnnoType.Highlight, color: 'rgba(14,14,14,1)'});

}

AnnoAPI.ExitAnnoMode()

Exits the annotation mode (highlight, strikethrough, or underline) that SetAnnoMode() sets.

Important

This feature is supported only in JS-SDK V1.1.19 and later and is available only on PC.

Syntax

expression.AnnoAPI.ExitAnnoMode()

Parameters

None.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Exit the annotation mode.
  await app.ActivePDF.AnnoAPI.ExitAnnoMode();

}

Annotation appearance methods

Each of the following AnnoAPI methods sets a property of the annotation that is currently selected: the bubble style, the line width, or the color.

AnnoAPI.SetAnnoStyleBySelection()

Sets the style of the selected annotation.

Syntax

expression.AnnoAPI.SetAnnoStyleBySelection({Style})

Parameters

PropertyData typeRequiredDescription
StyleEnumYesThe annotation bubble style. For more information, see Enum.TextStyle.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Set the annotation bubble style to the comment icon style.
  await app.ActivePDF.AnnoAPI.SetAnnoStyleBySelection({Style: app.Enum.TextStyle.Comment});

}

AnnoAPI.SetAnnoLineWidthBySelection()

Sets the line width of the selected annotation for pen tools such as the watercolor pen and smart pen.

Syntax

expression.AnnoAPI.SetAnnoLineWidthBySelection({Width})

Parameters

PropertyData typeRequiredDescription
WidthNumberYesThe line width. Valid values: 1 to 12.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Set the line width of the selected pen to 10.
  await app.ActivePDF.AnnoAPI.SetAnnoLineWidthBySelection({Width: 10});

}

AnnoAPI.SetAnnoColorBySelection()

Sets the color of the selected annotation for pen tools such as the watercolor pen and smart pen.

Syntax

expression.AnnoAPI.SetAnnoColorBySelection({Color})

Parameters

PropertyData typeRequiredDescription
ColorStringYesThe color in RGB or RGBA format.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Set the color of the selected annotation.
  await app.ActivePDF.AnnoAPI.SetAnnoColorBySelection({Color: 'rgba(14,14,14,1)'});

}

Pen and eraser methods

The SetInkMode() and ExitInkMode() methods of the AnnoAPI object control the pen mode, and the SwitchEraser() method controls the eraser mode. Each mode has a paired call that ends it: call ExitInkMode() to leave the pen mode, and call SwitchEraser({IsEraser: false}) to leave the eraser mode.

AnnoAPI.SetInkMode()

Sets the pen mode, including the pen type, line width, and color.

Important

This feature is supported only in JS-SDK V1.1.19 and later and is available only on PC.

Syntax

expression.AnnoAPI.SetInkMode({type, lineWidth, color})

Parameters

PropertyData typeRequiredDescription
typeEnumYesThe pen type, specified as an Enum.InkType value.
lineWidthNumberNoThe line width. Valid values: 0.5 to 12.
colorStringNoThe color.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Set the pen mode to handwriting, with a line width of 6 and a color of rgba(189,16,224,1).
  await app.ActivePDF.AnnoAPI.SetInkMode({type: app.Enum.InkType.Handwriting, lineWidth: 6,color:'rgba(189,16,224,1)'});

}

AnnoAPI.ExitInkMode()

Exits the pen mode.

Important

This feature is supported only in JS-SDK V1.1.19 and later and is available only on PC.

Syntax

expression.AnnoAPI.ExitInkMode()

Parameters

None.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Exit the pen mode.
  await app.ActivePDF.AnnoAPI.ExitInkMode();

}

AnnoAPI.SwitchEraser()

Enables or disables the eraser mode.

Important

This feature is supported only in JS-SDK V1.1.19 and later and is available only on PC.

Syntax

expression.AnnoAPI.SwitchEraser({IsEraser})

Parameters

PropertyData typeRequiredDescription
IsEraserBooleanNoSpecifies whether to enable the eraser mode. Set the value to true to enable the eraser mode, or false to disable it.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Enable the eraser mode.
  await app.ActivePDF.AnnoAPI.SwitchEraser({IsEraser: true});

  // Disable the eraser mode.
  await app.ActivePDF.AnnoAPI.SwitchEraser({IsEraser: false});

}

Comment and stamp methods

The following AnnoAPI methods add comments, annotation bubbles, and stamps to the active PDF document.

AnnoAPI.AddTextAnnoComment()

Adds a comment to an annotation.

Important

This feature is supported only in JS-SDK V1.1.19 and later and is available only on PC.

Syntax

expression.AnnoAPI.AddTextAnnoComment({PageIndex, Id, Comment})

Parameters

PropertyData typeRequiredDescription
PageIndexNumberYesThe page number where the annotation is located. Page numbers start from 1.
IdStringYesThe annotation ID.
CommentStringYesThe comment text.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Add a comment to an annotation.
  await app.ActivePDF.AnnoAPI.AddTextAnnoComment({PageIndex: 1, Id: '{8c3300cf-ec08-4350-aab3-2f42c480d92e}', Comment: '11111'});

}

AnnoAPI.AddTextData()

Adds an annotation bubble at a specified position.

Important

This feature is supported only in JS-SDK V1.1.19 and later.

Syntax

expression.AnnoAPI.AddTextData({x, y, content, color, style})

Parameters

PropertyData typeRequiredDescription
xNumberYesThe x-coordinate (clientX).
yNumberYesThe y-coordinate (clientY).
contentStringYesThe content text.
colorStringNoThe color in RGBA format.
styleEnumNoThe annotation bubble style. For more information, see Enum.TextStyle.

Example

async function example() {
  await instance.ready();

  const app = instance.Application;

  // Add an annotation bubble.
  await app.ActivePDF.AnnoAPI.AddTextData({x: 600, y: 400, content: '11111', color: 'rgba(14,14,14,1)', style: app.Enum.TextStyle.Comment});

}

AnnoAPI.InsertAnnoPic()

Inserts a stamp annotation.

Important

This feature is supported only in JS-SDK V1.1.19 and later.

Syntax

expression.AnnoAPI.InsertAnnoPic({dataUrl, width, height, x, y})

Parameters

PropertyData typeRequiredDescription
dataUrlStringYesThe Base64-encoded image string.
widthNumberYesThe width.
heightNumberYesThe height.
xNumberYesThe x-coordinate (clientX).
yNumberYesThe y-coordinate (clientY).

Example

In the following example, replace the dataUrl placeholder with the Base64-encoded image string of the stamp.

async function example() {
  await instance.ready();

  const app = instance.Application;
  const dataUrl = 'base64'; // Base64-encoded image string.

  // Insert a stamp annotation.
  await app.ActivePDF.AnnoAPI.InsertAnnoPic({dataUrl: dataUrl, width: 543, height: 277, x: 600, y: 400}); 

}