The document object is an instance accessible from the main mupdfwv.MuPDFWebViewer instance as follows:

const document = mupdf.document;

This assumes you have returned your instance name as mupdf from the initMuPDFWebViewer() promise!

document

The document object has the following methods:

open

open(config: { url: string, filename: string })

Opens a PDF document.

  • Arguments:
    • config(required) The configuration object.

Config object:

  • Arguments:

    • url(required) File path to open.
    • filename(required) The file name to use for the file.
  • Returns: Promise.

Example

mupdf.document.open("my-file.pdf", "My File");

close

close()

Closes the currently opened PDF document.

  • Returns: Promise.

Example

mupdf.document.close();

download

download(config?: { fileName?: string, includeAnnotations?: boolean })

Downloads the PDF file.

  • Arguments:
    • config(optional) The configuration object. If not set the original document filename is used with any annotations included.

Config object:

  • Arguments:
    • fileName(optional) Name of the file to download.
    • includeAnnotations(optional) Default true. Whether to include annotations.
  • Returns: Promise.

Example

mupdf.document.download({fileName:"my-file.pdf", includeAnnotations:false});

export

export(config?: { includeAnnotations?: boolean })

Exports the PDF. Returns the PDF data in Uint8Array format.

  • Arguments:
    • config(optional) The configuration object. If not set the document will be exported with annotations.

Config object:

  • Arguments:
    • includeAnnotations(optional) Default true. Whether to include annotations.
  • Returns: Promise<Uint8Array<ArrayBufferLike>>.

Example

mupdf.document.export({includeAnnotations:false});

getPages

getPages(config?: { pageRange?: string })

Gets PDF page information.

  • Arguments:
    • config(optional) The configuration object. If not set then all pages are returned.

Config object:

  • Arguments:
    • pageRange(optional) Default: “all”. Page index range (e.g., “0-5, 7, 9-12”, “all”).

Page references are zero-indexed.

  • Returns: Promise<{ pages: mupdfwv.PageInfo[]; }>.

Example

mupdf.document.getPages({pageRange:"0-3"});

// returns e.g.

{
pages: {
    pageIndex: number;
    read: boolean;
    isVisible: boolean;
    bbox: {
    width: number;
    height: number;
    x: number;
    y: number;
    }
}[]
}

getPageCount

getPageCount()

Gets the total number of pages in the PDF.

  • Returns: Promise<{ pageCount: number; }.

Example

mupdf.document.getPageCount();

// returns e.g

{ pageCount: number }

print

print(config?: { pageRange: string })

Prints the PDF.

  • Arguments:
    • config(optional) The configuration object. If not set then the whole document will be printed.

Config object:

  • Arguments:
    • pageRange(required) Page index range (e.g., “0-5, 7, 9-12”, “all”).

Page references are zero-indexed.

  • Returns: Promise<mupdfwv.PrintResult>.

Example

mupdf.document.print({pageRange:"0-3"});

// returns e.g.

{ status: 'PRINTED' | 'CANCELLED' }

rotatePage

rotatePage(config: { pageRange: string, degree: mupdf.refs.degree })

Rotates pages.

  • Arguments:
    • config(required) The configuration object.

Config object:

  • Arguments:
    • pageRange(required) Page index range (e.g., “0-5, 7, 9-12”, “all”).

Page references are zero-indexed.

  • Returns: Promise.

Example

mupdf.document.rotatePage({pageRange:"0", degree:mupdf.refs.degree.DEG_90});

getText

getText(config?: { pageRange?: string })

Extracts text from the PDF.

  • Arguments:
    • config(optional) The configuration object. If not set then the whole document will be used.

Config object:

  • Arguments:
    • pageRange(optional) Default: “all”. Page index range (e.g., “0-5, 7, 9-12”, “all”).
  • Returns: Promise<{ pageIndex: number; text: string; }[]>.

Example

async function getText() {
    return mupdf.document.getText({pageRange:"0"});
}

function successCallbackGetText(data) {
    console.log(`Text Data is: ${data[0].text}`);
}

function failureCallbackGetText(error) {
    console.error(`Error getting text: ${error}`);
}

getText().then(successCallbackGetText, failureCallbackGetText);