The annotation object is an instance accessible from the main MuPDFWebViewer instance as follows:
const annotation = webViewer.annotation;
This assumes you have returned your instance name as webViewer from the initMuPDFWebViewer() promise!
annotation
The annotation object has the following methods:
remove
remove(config: {
annotations: ({ name: string; pageIndex: number } | { oid: number; pageIndex: number })[];
emitEvent?: boolean;
}): Promise<undefined>;
Removes annotations.
Parameters
The configuration object.
Array of annotation identifiers to remove (by { name, pageIndex } or { oid, pageIndex }).
Returns
Example
webViewer.annotation.remove({annotations:[
{name:"squiggle_1", pageIndex:0},
{name:"rectangle_10", pageIndex:3},
{oid:36245, pageIndex:1}
]
});
get
get(config?: { pageIndex: number }): Promise<{ annotations: Annotation[] }>;
Gets annotations. Returns array of annotations.
Parameters
Optional configuration. If omitted, returns all annotations for all pages.
Returns
result
Promise<{ annotations: Annotation[] }>
required
A Promise that resolves to an object containing an Annotation[] array.
Example
webViewer.annotation.get({pageIndex:0});
add
add(config: { annotations: Annotation[]; emitEvent?: boolean }): Promise<{ annotations: Annotation[] }>;
Adds annotations. Returns array of added annotations.
Parameters
The configuration object.
Returns
result
Promise<{ annotations: Annotation[] }>
required
A Promise that resolves to an object containing an Annotation[] array.
set
set(config: { annotations: Annotation[]; emitEvent?: boolean }): Promise<undefined>;
Updates annotations.
Parameters
The configuration object.
undo
undo(): Promise<{ success: boolean }>;
Undoes annotation operations and returns success status.
Returns
result
Promise<{ success: boolean; }>
required
A Promise that resolves to a success status.
Example
webViewer.annotation.undo();
redo
redo(): Promise<{ success: boolean }>;
Redoes undone annotation operations and returns success status.
Returns
result
Promise<{ success: boolean; }>
required
A Promise that resolves to a success status.
Example
webViewer.annotation.redo();
Annotation Object
The Annotation object type:
export interface Annotation {
oid: number;
type: AnnotType;
pageIndex: number;
name: string;
rect: TRect;
rects?: TRect[];
opacity?: number;
rotation?: number;
createdAt?: string | null;
modifiedAt?: string | null;
author?: string;
canBePrinted?: boolean;
locked?: boolean;
strokeColor?: string;
strokeWidth?: number;
imageData?: string;
position?: TPoint;
inkList?: TPoint[][];
fillColor?: string;
strokeCloudRadius?: number;
strokeDashPattern?: number[];
startPoint?: TPoint;
endPoint?: TPoint;
startPointStyle?: LineEnd;
endPointStyle?: LineEnd;
popupNote?: {
oid?: number;
rect: TRect;
createdAt?: string | null;
modifiedAt?: string | null;
author?: string;
};
contents?: string;
vertices?: TPoint[];
fontColor?: string;
textAlign?: TextAlign;
fontFamily?: string;
fontSize?: number;
link?: {
type: string;
value: string | number;
};
}
Supporting Types
export interface TPoint {
x: number;
y: number;
}
export interface TRect {
top: number;
left: number;
right: number;
bottom: number;
}