Resource Base
Table of contents

AnnotationManager Class

The Dynamsoft.DDV.annotationManager instance will be created automatically as soon as DDV is initialized. Please refer to annotationManager.

API Index

Methods

API Name Description
createAnnotation() Create an annotation instance.
getAnnotationsByUids() Get annotations by annotation uids.
getAnnotationsByPage() Get annotations in specified page.
getAnnotationsByDoc() Get all annotations in specified document.
deleteAnnotations() Delete specified annotations.
bringAnnotationForward() Bring the specified annotation forward.
sendAnnotationBackward() Send the specified annotation backward.
bringAnnotationToFront() Bring the specified annotation in front of all other annotations.
sendAnnotationToBack() Send the specified annotation behind all other annotations.

Events

API Name Description
on() Bind a listener to the specified event.
off() Unbind event listener(s) from the specified event.

Integrated Events

Event Name Description
annotationsAdded Triggered when new annotation(s) is added.
annotationsDeleted Triggered when annotation(s) is deleted.
annotationLayerChanged Triggered when annotation’s layer is changed.
annotationsModified Triggered when annotation(s) is modified.

Methods

createAnnotation()

Create an annotation instance and add the created instance to the specified page.

Syntax

createAnnotation(pageUid: string, type: AnnotationType, annotationOptions?: RectAnnotationOptions|EllipseAnnotationOptions|PolygonAnnotationOptions|PolylineAnnotationOptions|LineAnnotationOptions|InkAnnotationOptions|TextBoxAnnotationOptions|TextTypewriterAnnotationOptions):Rectangle|Ellipse|Polygon|Polyline|Line|Ink|TextBox|TextTypewriter;

createAnnotation(pageUid: string, "stamp", annotationOptions?: StampAnnotationOptions): Promise<Stamp>;

Parameters

pageUid: Specify the page to add the annotation.

type: Specify the type of annotation to create.

type AnnotationType = "rectangle" | "ellipse" | "polygon" | "polyline" | "line" | "ink" | "textBox" | "textTypewriter" | "stamp";

annotationOptions: The annotation options. Please refer to

Return value

The instance of annotation. Please refer to

Code Snippet

  • To creat new annotations.

      // Given that editViewer is an existing instance of EditViewer and a document is currently open.
      const pageUid = editViewer.indexToUid(0);
    
      const rect = Dynamsoft.DDV.annotationManager.createAnnotation(pageUid, "rectangle");
      const ellipse = Dynamsoft.DDV.annotationManager.createAnnotation(pageUid, "ellipse");
      const polygon = Dynamsoft.DDV.annotationManager.createAnnotation(pageUid, "polygon");
      const polyline = Dynamsoft.DDV.annotationManager.createAnnotation(pageUid, "polyline");
      const line = Dynamsoft.DDV.annotationManager.createAnnotation(pageUid, "line");
      const ink = Dynamsoft.DDV.annotationManager.createAnnotation(pageUid, "ink");
      const textBox = Dynamsoft.DDV.annotationManager.createAnnotation(pageUid, "textBox");
      const textTypewriter = Dynamsoft.DDV.annotationManager.createAnnotation(pageUid, "textTypewriter");
      const stamp = await Dynamsoft.DDV.annotationManager.createAnnotation(pageUid, "stamp");
    

Exception

Error Code Error Message
-80001 License string is invalid.
-80002 XXX(LicenseModuleName) module license has expired.
-80003 XXX(LicenseModuleName) module license is missing.
-80004 XXX(LicenseModuleName) module license version does not match.
-80005 Domain does not match the domain bound to the XXX(LicenseModuleName) module license.
-80050 DDV.Core.init() has not been set up yet.
-80051 DDV.Core.init() has not been completed.
-80100 XXX(API): XXX(ParameterName) is invalid.
-80102 XXX(API): XXX(ParameterName) is missing.
-80103 XXX(API): The value for XXX(ParameterName) is not supported.
-80105 XXX(API): The specified page(s) do not exist.

getAnnotationsByUids()

Get annotations by annotation uids.

Syntax

getAnnotationsByUids(annotationUids: string[]): Annotation[];

Parameters

annotationUids: The array of the annotation uids.

Return value

An array of Annotation objects.

Please refer to

Warning

Error Code Error Message API return value
-80100 XXX(API): XXX(ParameterName) is invalid. []
-80102 XXX(API): XXX(ParameterName) is missing. []
-80106 XXX(API): The specified annotation does not exist. []

getAnnotationsByPage()

Get annotations in specified page.

Syntax

getAnnotationsByPage(pageUid: string): Annotation[];

Parameters

pageUid: Specify the page.

Return value

An array of Annotation object.

Please refer to

Warning

Error Code Error Message API return value
-80100 XXX(API): XXX(ParameterName) is invalid. []
-80102 XXX(API): XXX(ParameterName) is missing. []
-80105 XXX(API): The specified page(s) do not exist. []

getAnnotationsByDoc()

Get all annotations in specified document.

Syntax

getAnnotationsByDoc(docUid: string): Annotation[];

docUid: Specify the doc.

Return value

An array of Annotation objects.

Please refer to

Warning

Error Code Error Message API return value
-80100 XXX(API): XXX(ParameterName) is invalid. []
-80102 XXX(API): XXX(ParameterName) is missing. []
-80104 XXX(API): The specified document(s) do not exist. []

deleteAnnotations()

Delete specified annotations.

Syntax

deleteAnnotations(annotationUids: string[]): boolean;

Parameters

annotationUids: Specify the array of annotation uids to delete.

Return value

true

false

Warning

Error Code Error Message API return value
-80100 XXX(API): XXX(ParameterName) is invalid. false
-80102 XXX(API): XXX(ParameterName) is missing. false
-80106 XXX(API): The specified annotation does not exist. false

bringAnnotationForward()

Bring the specified annotation forward.

Syntax

bringAnnotationForward(annotationUid: string): boolean;

Parameters

annotationUid: Specify the annotation uid to bring forward.

Return value

true: Successfully.

false: Failed.

Warning

Error Code Error Message API return value
-80100 XXX(API): XXX(ParameterName) is invalid. false
-80102 XXX(API): XXX(ParameterName) is missing. false
-80106 XXX(API): The specified annotation does not exist. false

sendAnnotationBackward()

Send the specified annotation backward.

Syntax

sendAnnotationBackward(annotationUid: string): boolean;

Parameters

annotationUid: Specify the annotation uid to send backward.

Return value

true: Successfully.

false: Failed.

Warning

Error Code Error Message API return value
-80100 XXX(API): XXX(ParameterName) is invalid. false
-80102 XXX(API): XXX(ParameterName) is missing. false
-80106 XXX(API): The specified annotation does not exist. false

bringAnnotationToFront()

Bring the specified annotation in front of all other annotations.

Syntax

bringAnnotationToFront(annotationUid: string): boolean;

Parameters

annotationUid: Specify the annotation uid to bring to front.

Return value

true: Successfully.

false: Failed.

Warning

Error Code Error Message API return value
-80100 XXX(API): XXX(ParameterName) is invalid. false
-80102 XXX(API): XXX(ParameterName) is missing. false
-80106 XXX(API): The specified annotation does not exist. false

sendAnnotationToBack()

Send the specified annotation behind all other annotations.

Syntax

sendAnnotationToBack(annotationUid: string): boolean;

Parameters

annotationUid: Specify the annotation uid to send to back.

Return value

true: Successfully.

false: Failed.

Warning

Error Code Error Message API return value
-80100 XXX(API): XXX(ParameterName) is invalid. false
-80102 XXX(API): XXX(ParameterName) is missing. false
-80106 XXX(API): The specified annotation does not exist. false

Events

on()

Bind a listener to the specified event.

Syntax

on(eventName: EventName, listener:(event:EventObject)=>void): void;

Parameters

eventName: Specify the event name. It should be an integrated event name.

listener: Specify the listener.

Code Snippet

// Bind a listener to the integrated event annotationsModified.
const eventFunc = (e)=>{
    console.log(e);
    console.log(e.modifiedAnnotations[0].uid);
    console.log(e.modifiedAnnotations[0].newOptions);
    console.log(e.actions);
};

Dynamsoft.DDV.annotationManager.on("annotationsModified", eventFunc);

Warning

Error Code Error Message
-80100 XXX(API): XXX(ParameterName) is invalid.
-80102 XXX(API): XXX(ParameterName) is missing.
-80103 XXX(API): The value for XXX(ParameterName) is not supported.

off()

Unbind event listener(s) from the specified event.

Syntax

off(eventName: EventName, listener?:(event:EventObject)=>void): void;

Parameters

eventName: Specify the event name. It should be an integrated event name.

listener: Specify the listener. If no listener is specified, unbind all event listeners from the specified event

Code Snippet

const eventFunc = (e)=>{
    console.log(e);
    console.log(e.modifiedAnnotations[0].uid);
    console.log(e.modifiedAnnotations[0].newOptions);
    console.log(e.actions);
};

Dynamsoft.DDV.annotationManager.on("annotationsModified", eventFunc);

// Unbind the specified event listener.
Dynamsoft.DDV.annotationManager.off("annotationsModified", eventFunc);

Warning

Error Code Error Message
-80100 XXX(API): XXX(ParameterName) is invalid.
-80102 XXX(API): XXX(ParameterName) is missing.
-80103 XXX(API): The value for XXX(ParameterName) is not supported.

Integrated events

annotationsAdded

Triggered when new annotation(s) is added.

Callback

An EventObject.

Attributes

annotationUids: The array of new added annotations uids.

annotationsDeleted

Triggered when annotation(s) is deleted.

Callback

An EventObject.

Attributes

annotationUids: The array of deleted annotations uids.

annotationLayerChanged

Triggered when annotation’s layer is changed.

Callback

An EventObject.

Attributes

oldAnnotationUidList : The list of old annotation uids, arranged in hierarchical order from bottom to top for each page.

newAnnotationUidList: The list of new annotation uids, arranged in hierarchical order from bottom to top for each page.

annotationsModified

Triggered when annotation(s) is modified.

Callback

An EventObject.

Attributes

modifiedAnnotations: The array of the objects which include below properties.

  • uid: The modified annotation uid.
  • oldOptions: The modified annotation old options.
  • newOptions: The modified annotation new options.

actions: The array of actions. Supported actions:

  • moved
  • resized
  • rotated
  • flagsChanged
  • appearanceChanged
  • contentChanged

    The table presents the ‘actions’ returned by events triggered by changes in attributes associated with various types of annotations.

    action Rectangle Ellipse Polygon Polyline Line Ink TextBox TextTypewriter Stamp
    moved x, y x, y Overall translation of points Overall translation of points Overall translation of startPoint&endPoint Overall translation of points x, y x, y x, y
    resized width,height width, height points points startPoint, endPoint points or resized through annotation selection’s control points width, height N/A width, height
    rotated rotation rotation N/A N/A N/A rotation rotation N/A rotation
    flagsChanged flags flags flags flags flags flags flags flags flags
    appearanceChanged borderWidth, borderColor, background, opacity, lineDash borderWidth, borderColor, background, opacity, lineDash borderWidth, borderColor, background, opacity, lineDash lineEndingborderWidth, borderColor, background, opacity, lineDash lineEndingborderWidth, borderColor, background, opacity, lineDash borderWidth, borderColor, opacity textAlign, textContents(excludes content), borderWidth, borderColor, background, opacity, lineDash textContents(excludes content), opacity opacity
    contentChanged N/A N/A N/A N/A N/A N/A content in textContents content in textContents stamp

This page is compatible for:

Is this page helpful?

YesYes NoNo

In this article:

latest version

    • Latest version(2.0)
    • Version 1.x
      • Version 1.1
    Change +