mutool-run - run programs accessing the MuPDF Javascript API
mutool run script.js [ arguments … ]
The run command executes a Javascript program, which has access to most of the features of the MuPDF library. The command supports ECMAScript 5 syntax in strict mode.
See https://mupdf.readthedocs.io for details about the Javascript interface.
scriptArgs array.
If mutool run is invoked without any arguments, it will drop you into
an interactive REPL (read-eval-print-loop). To exit call the
quit() function or press Ctrl-D.
To get convenient REPL line editing, try running:
rlwrap mutool run
Command line arguments are accessible from the global
scriptArgs array. The name of the script is in the global
scriptPath variable.
The following functions are only available in the mutool run shell:
require(module)repr(value)gc(report)load(fileName)print(...)stdout, separated by spaces and followed
by a newline.
quit()read(fileName)readFile(fileName)readline()write(...)stdout, separated by spaces.
For compatibility with Node the following objects are provided:
process.argvfs.readFileSync(filename)fs.writeFileSync(filename, buffer)The following ESM import statements are ignored:
import fs from "fs"import * as fs from "fs"import mupdf from "mupdf"import * as mupdf from "mupdf"If you only use these functions and otherwise stick to ES5 syntax and CommonJS imports, your scripts should be able to run both with mutool run and Node.