Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/docs/tools/mutool-run.rst @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 mutool run | |
| 2 ========================================== | |
| 3 | |
| 4 The ``run`` command executes a Javascript program, which has access to most of the features of the MuPDF library. | |
| 5 The command supports ECMAScript 5 syntax in strict mode. | |
| 6 | |
| 7 .. code-block:: bash | |
| 8 | |
| 9 mutool run script.js [ arguments ... ] | |
| 10 | |
| 11 ``script.js`` | |
| 12 The Javascript file which you would like to run. | |
| 13 | |
| 14 ``[ arguments ... ]`` | |
| 15 Any extra arguments you want to pass to the script. | |
| 16 These are available in the global ``scriptArgs`` array. | |
| 17 | |
| 18 If invoked without any arguments, it will drop you into an interactive REPL (read-eval-print-loop). | |
| 19 To exit call the ``quit()`` function or press *Ctrl-D*. | |
| 20 | |
| 21 Environment | |
| 22 ----------- | |
| 23 | |
| 24 Command line arguments are accessible from the global ``scriptArgs`` array. | |
| 25 The name of the script is in the global ``scriptPath`` variable. | |
| 26 | |
| 27 The following functions are only available in the mutool run shell: | |
| 28 | |
| 29 ``require(module)`` | |
| 30 Load a Javascript module. | |
| 31 | |
| 32 ``repr(value)`` | |
| 33 Convert any Javascript value to a string. | |
| 34 | |
| 35 ``gc(report)`` | |
| 36 Run the garbage collector to free up memory. Optionally report statistics on the garbage collection. | |
| 37 | |
| 38 ``load(fileName)`` | |
| 39 Load and execute script in "fileName". | |
| 40 | |
| 41 ``print(...)`` | |
| 42 Print arguments to ``stdout``, separated by spaces and followed by a newline. | |
| 43 | |
| 44 ``quit()`` | |
| 45 Exit the shell. | |
| 46 | |
| 47 ``read(fileName)`` | |
| 48 Read the contents of a file and return them as a UTF-8 decoded string. | |
| 49 | |
| 50 ``readFile(fileName)`` | |
| 51 Read the contents from a file and return them as a Buffer. | |
| 52 | |
| 53 ``readline()`` | |
| 54 Read one line of input from standard input and return it as a string. | |
| 55 | |
| 56 ``write(...)`` | |
| 57 Print arguments to ``stdout``, separated by spaces. | |
| 58 | |
| 59 Node Compatibility | |
| 60 ------------------ | |
| 61 | |
| 62 For compatibility with Node the following objects are provided: | |
| 63 | |
| 64 ``process.argv`` | |
| 65 The command line arguments. | |
| 66 | |
| 67 ``fs.readFileSync`` | |
| 68 Read a file into a buffer. | |
| 69 | |
| 70 ``fs.writeFileSync`` | |
| 71 Write a buffer to file. | |
| 72 | |
| 73 The following ESM import statements are ignored: | |
| 74 | |
| 75 .. code-block:: | |
| 76 | |
| 77 import * as fs from "fs" | |
| 78 import * as mupdf from "mupdf" | |
| 79 | |
| 80 If you only use these functions and otherwise stick to ES5 syntax and CommonJS | |
| 81 imports, your scripts should be able to run both with mutool run and Node. |
