Skip to main content

Documentation Index

Fetch the complete documentation index at: https://webviewer-docs.mupdf.com/llms.txt

Use this file to discover all available pages before exploring further.

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

config
object
required
The configuration object.

Returns

result
Promise
required
A Promise.
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

config
object
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});
The Annotation[] array contains annotation objects, also see the Working with Annotations guide.

add

add(config: { annotations: Annotation[]; emitEvent?: boolean }): Promise<{ annotations: Annotation[] }>;
Adds annotations. Returns array of added annotations.

Parameters

config
object
required
The configuration object.

Returns

result
Promise<{ annotations: Annotation[] }>
required
A Promise that resolves to an object containing an Annotation[] array.
The Annotation[] array contains annotation objects, also see the Working with Annotations guide.

set

set(config: { annotations: Annotation[]; emitEvent?: boolean }): Promise<undefined>;
Updates annotations.

Parameters

config
object
required
The configuration object.
The Annotation[] array contains annotation objects, also see the Working with Annotations guide.

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;
}