AnnoAPI
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 group | Method | Description |
| Selection | SelectAnno() | Selects an annotation on a specified page. |
| Selection | ClearAnnoSelection() | Clears the annotation selection. |
| Selection | GetAnnoSelection() | Retrieves the selected annotations. |
| Selection | CopyAnnoSelection() | Copies the selected annotation. |
| Text markup | SetSelectionAnno() | Applies a highlight, strikethrough, or underline annotation to the selection. |
| Text markup | SetAnnoMode() | Sets the highlight, strikethrough, or underline annotation mode. |
| Text markup | ExitAnnoMode() | Exits the annotation mode. |
| Annotation appearance | SetAnnoStyleBySelection() | Sets the bubble style of the selected annotation. |
| Annotation appearance | SetAnnoLineWidthBySelection() | Sets the line width of the selected annotation. |
| Annotation appearance | SetAnnoColorBySelection() | Sets the color of the selected annotation. |
| Pen and eraser | SetInkMode() | Sets the pen mode, including the pen type, line width, and color. |
| Pen and eraser | ExitInkMode() | Exits the pen mode. |
| Pen and eraser | SwitchEraser() | Enables or disables the eraser mode. |
| Comment and stamp | AddTextAnnoComment() | Adds a comment to an annotation. |
| Comment and stamp | AddTextData() | Adds an annotation bubble at a specified position. |
| Comment and stamp | InsertAnnoPic() | 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.
This feature is supported only in JS-SDK V1.1.19 and later.
Syntax
expression.AnnoAPI.SelectAnno({PageIndex, Id})
Parameters
| Property | Data type | Required | Description |
| PageIndex | Number | Yes | The page number where the annotation is located. Page numbers start from 1. |
| Id | String | Yes | The 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.
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.
This feature is supported only in JS-SDK V1.1.19 and later.
Syntax
expression.AnnoAPI.GetAnnoSelection()
Parameters
None.
Return value
| Field | Data type | Description |
| result | Array | An array of annotation objects. |
Each annotation object in result contains the following fields:
| Field | Data type | Description |
| type | String | The annotation type. |
| id | String | The annotation ID. |
| pageIndex | Number | The page number of the page on which the annotation is located. Page numbers start from 0. |
| rect | Object | The position information of the annotation. |
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.
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, andExitAnnoMode()exits it.
AnnoAPI.SetSelectionAnno()
Applies an annotation (highlight, strikethrough, or underline) to the selection.
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
| Property | Data type | Required | Description |
| type | Enum | Yes | The annotation type. For more information, see Enum.AnnoType. |
| color | String | No | The 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().
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
| Property | Data type | Required | Description |
| type | Enum | Yes | The annotation type. For more information, see Enum.AnnoType. |
| color | String | No | The 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.
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
| Property | Data type | Required | Description |
| Style | Enum | Yes | The 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
| Property | Data type | Required | Description |
| Width | Number | Yes | The 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
| Property | Data type | Required | Description |
| Color | String | Yes | The 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.
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
| Property | Data type | Required | Description |
| type | Enum | Yes | The pen type, specified as an Enum.InkType value. |
| lineWidth | Number | No | The line width. Valid values: 0.5 to 12. |
| color | String | No | The 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.
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.
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
| Property | Data type | Required | Description |
| IsEraser | Boolean | No | Specifies 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.
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
| Property | Data type | Required | Description |
| PageIndex | Number | Yes | The page number where the annotation is located. Page numbers start from 1. |
| Id | String | Yes | The annotation ID. |
| Comment | String | Yes | The 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.
This feature is supported only in JS-SDK V1.1.19 and later.
Syntax
expression.AnnoAPI.AddTextData({x, y, content, color, style})
Parameters
| Property | Data type | Required | Description |
| x | Number | Yes | The x-coordinate (clientX). |
| y | Number | Yes | The y-coordinate (clientY). |
| content | String | Yes | The content text. |
| color | String | No | The color in RGBA format. |
| style | Enum | No | The 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.
This feature is supported only in JS-SDK V1.1.19 and later.
Syntax
expression.AnnoAPI.InsertAnnoPic({dataUrl, width, height, x, y})
Parameters
| Property | Data type | Required | Description |
| dataUrl | String | Yes | The Base64-encoded image string. |
| width | Number | Yes | The width. |
| height | Number | Yes | The height. |
| x | Number | Yes | The x-coordinate (clientX). |
| y | Number | Yes | The 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});
}