Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/docs/guide/using-with-javascript.md @ 3:2c135c81b16c
MERGE: upstream PyMuPDF 1.26.4 with MuPDF 1.26.7
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:44:09 +0200 |
| parents | b50eed0cc0ef |
| children |
comparison
equal
deleted
inserted
replaced
| 0:6015a75abc2d | 3:2c135c81b16c |
|---|---|
| 1 # Using with Javascript | |
| 2 | |
| 3 MuPDF can be used with Javascript in two ways: | |
| 4 | |
| 5 * With the MuPDF.js module for Javascript. | |
| 6 * With the mutool run command line interpreter. | |
| 7 | |
| 8 ## MuPDF.js | |
| 9 | |
| 10 We've created a portable WebAssembly build of MuPDF that works with all modern | |
| 11 Javascript environments such as Node, Bun, Firefox, Chrome, etc. This module | |
| 12 provides an object oriented interface to the core library, similar to the Java | |
| 13 library. There are also TypeScript definition files. | |
| 14 | |
| 15 The easy way to get started using this is by using Node.js and install | |
| 16 the latest release from NPM: | |
| 17 | |
| 18 npm install mupdf | |
| 19 | |
| 20 > Note that the mupdf module is only usable with ESM imports! | |
| 21 | |
| 22 Then run the following script to verify that everything works by listing | |
| 23 all the public classes and functions in the mupdf module: | |
| 24 | |
| 25 import * as mupdf from mupdf | |
| 26 console.log(Object.keys(mupdf)) | |
| 27 | |
| 28 Once that is working, try out some of the | |
| 29 <a href="../cookbook/javascript/index.html">Javascript examples</a>! | |
| 30 | |
| 31 See the [mupdfjs.readthedocs.io](https://mupdfjs.readthedocs.io/) site for more extensive | |
| 32 examples of using MuPDF.js in modern Javascript frameworks. | |
| 33 | |
| 34 ## mutool run | |
| 35 | |
| 36 The mutool command line has a built-in ES5 interpreter that can run scripts | |
| 37 with the same high level API as MuPDF.js (with some minor differences) without | |
| 38 needing to install Node or Bun. | |
| 39 | |
| 40 The main limitation is that you can only use ES5 language features (so no | |
| 41 "let", arrow functions, or "class" syntactic sugar). | |
| 42 | |
| 43 ## How to build MuPDF.js | |
| 44 | |
| 45 See the README and BUILDING files in the `platform/wasm` directory of the MuPDF source. |
