Skip to main content
The annotation object is an instance accessible from the main MuPDFWebViewer instance as follows:
const annotation = mupdf.annotation;
This assumes you have returned your instance name as mupdf from the initMuPDFWebViewer() promise!

annotation

The annotation object has the following methods:

get

get(config?: { pageIndex: number }) Gets annotations. Returns array of annotations.
  • Arguments:
    • config(optional) The configuration object. If undefined returns all annotations for all pages.
Config object:
  • Arguments:
    • pageIndex(required) Page index.
  • Returns: Promise<{ annotations: Annotation[] }>.
Example
mupdf.annotation.get({pageIndex:0});
The Annotation[] array contains annotation objects, also see the Working with Annotations guide.

set

set(config: { annotations: Annotation[], emitEvent?: boolean }) Updates annotations.
  • Arguments:
    • config(required) The configuration object.
Config object:
  • Arguments:
    • annotations(required) An array of annotation objects.
    • emitEvent - (optional) Whether to emit events
The Annotation[] array contains annotation objects, also see the Working with Annotations guide.

add

add(config: { annotations: Annotation[]; emitEvent?: boolean }) Adds annotations. Returns array of added annotations.
  • Arguments:
    • config(required) The configuration object.
Config object:
  • Arguments:
    • annotations(required) An array of annotation objects.
    • emitEvent(optional) Whether to emit events.
  • Returns: Promise<Annotation[]>.
The Annotation[] array contains annotation objects, also see the Working with Annotations guide.

remove

remove(config: { annotations: Array<{ name: string, pageIndex: number } | { oid: number, pageIndex: number }>, emitEvent?: boolean }) Removes annotations.
  • Arguments:
    • config(required) The configuration object.
Config object:
  • Arguments:
    • annotations(required) Array of annotation information to remove.
    • emitEvent(optional) Whether to emit events.
  • Returns: Promise.
Example
mupdf.annotation.remove({annotations:[
                                      {name:"squiggle_1", pageIndex:0},
                                      {name:"rectangle_10", pageIndex:3},
                                      {oid:36245, pageIndex:5}
                                      ]
                        });

undo

undo() Undoes annotation operations and returns success status.
  • Returns: Promise<{ success: boolean; }>.
Example
mupdf.annotation.undo();

redo

redo() Redoes undone annotation operations and returns success status.
  • Returns: Promise<{ success: boolean; }>.
Example
mupdf.annotation.redo();

Annotation Object

The Annotation object is a JSON object as follows:
{
  oid: number;
  pageIndex: number;
  name: string;
  rect?: TRect;
  opacity?: number;
  author?: string;
  canBePrinted?: boolean;
  locked?: boolean;
  rotation?: number;
  createdAt?: string;
  modifiedAt?: string;
  contents?: string;
  fillColor?: string;
  position?: { x: number; y: number };
  popupNote?: {
                "rect": {
                    "top": number;
                    "bottom": number;
                    "left": number;
                    "right": number;
                }
            }

  • oid (optional): Object id
  • pageIndex (required): Page index
  • name (optional): Unique name in the page
  • rect (optional): Rectangle { top: number, left: number, bottom: number, right: number }
  • opacity (optional): Opacity (0.0 ~ 1.0)
  • author (optional): Author
  • canBePrinted (optional): Whether to be printed
  • locked (optional): Whether to be locked
  • rotation (optional): Rotation in degrees
  • createdAt (optional): Creation date string
  • modifiedAt (optional): Modification date string
  • contents (optional): Contents string
  • fillColor (optional): Fill color string in hex format e.g. #RRGGBB
  • position (optional): Position { x: number; y: number }
  • popupNote (optional): Popup note object with rect property
If you don’t set the oid or name then a new annotation will be created with auto assigned values.