view mupdf-source/docs/guide/using-with-javascript.md @ 38:8934ac156ef5

Allow to build with the PyPI package "clang" instead of "libclang". 1. It seems to be maintained. 2. In the FreeBSD base system there is no pre-built libclang.so. If you need this library you have to install llvm from ports additionally. 2. On FreeBSD there is no pre-built wheel "libclang" with a packaged libclang.so.
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 23 Sep 2025 10:27:15 +0200
parents b50eed0cc0ef
children
line wrap: on
line source

# Using with Javascript

MuPDF can be used with Javascript in two ways:

* With the MuPDF.js module for Javascript.
* With the mutool run command line interpreter.

## MuPDF.js

We've created a portable WebAssembly build of MuPDF that works with all modern
Javascript environments such as Node, Bun, Firefox, Chrome, etc. This module
provides an object oriented interface to the core library, similar to the Java
library. There are also TypeScript definition files.

The easy way to get started using this is by using Node.js and install
the latest release from NPM:

	npm install mupdf

> Note that the mupdf module is only usable with ESM imports!

Then run the following script to verify that everything works by listing
all the public classes and functions in the mupdf module:

	import * as mupdf from mupdf
	console.log(Object.keys(mupdf))

Once that is working, try out some of the
<a href="../cookbook/javascript/index.html">Javascript examples</a>!

See the [mupdfjs.readthedocs.io](https://mupdfjs.readthedocs.io/) site for more extensive
examples of using MuPDF.js in modern Javascript frameworks.

## mutool run

The mutool command line has a built-in ES5 interpreter that can run scripts
with the same high level API as MuPDF.js (with some minor differences) without
needing to install Node or Bun.

The main limitation is that you can only use ES5 language features (so no
"let", arrow functions, or "class" syntactic sugar).

## How to build MuPDF.js

See the README and BUILDING files in the `platform/wasm` directory of the MuPDF source.