From 893675249d9e3e20f198e8c25783b04c823dec39 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 5 Sep 2018 12:02:19 +0200 Subject: mutool run: Pass script path and arguments as scriptPath and scriptArgs. --- docs/examples/bbox-device.js | 6 +++--- docs/examples/draw-document.js | 2 +- docs/examples/jpx-to-pdf.js | 8 ++++---- docs/examples/pdf-merge.js | 8 ++++---- docs/examples/trace-device.js | 6 +++--- docs/manual-mutool-run.html | 5 +++-- 6 files changed, 18 insertions(+), 17 deletions(-) (limited to 'docs') diff --git a/docs/examples/bbox-device.js b/docs/examples/bbox-device.js index 52d2cb4a..4a4b9f82 100644 --- a/docs/examples/bbox-device.js +++ b/docs/examples/bbox-device.js @@ -79,11 +79,11 @@ function BBoxDevice(bbox) { }; } -if (argv.length != 3) +if (scriptArgs.length != 2) print("usage: mutool run bbox-device.js document.pdf pageNumber") else { - var doc = new Document(argv[1]); - var page = doc.loadPage(parseInt(argv[2])-1); + var doc = new Document(scriptArgs[0]); + var page = doc.loadPage(parseInt(scriptArgs[1])-1); var bbox = [Infinity, Infinity, -Infinity, -Infinity]; page.run(new BBoxDevice(bbox), Identity); print("original bbox:", page.bound()); diff --git a/docs/examples/draw-document.js b/docs/examples/draw-document.js index 1e285ede..fe431257 100644 --- a/docs/examples/draw-document.js +++ b/docs/examples/draw-document.js @@ -1,6 +1,6 @@ // Draw all pages in a document and save them as PNG files. -var doc = new Document(argv[1]); +var doc = new Document(scriptArgs[0]); var n = doc.countPages(); for (var i = 0; i < n; ++i) { var page = doc.loadPage(i); diff --git a/docs/examples/jpx-to-pdf.js b/docs/examples/jpx-to-pdf.js index ee95ab30..be64044f 100644 --- a/docs/examples/jpx-to-pdf.js +++ b/docs/examples/jpx-to-pdf.js @@ -27,13 +27,13 @@ function addJPXPage(filename) { doc.insertPage(-1, doc.addPage(mediabox, 0, resources, contents)); } -var i, n = argv.length; -if (n < 2) { +var i, n = scriptArgs.length; +if (n < 1) { print("usage: mutool run jpx-to-pdf.js file.jpx ..."); quit(); } -for (i = 1; i < n; ++i) { - addJPXPage(argv[i]); +for (i = 0; i < n; ++i) { + addJPXPage(scriptArgs[i]); } doc.save("out.pdf", "ascii,pretty"); diff --git a/docs/examples/pdf-merge.js b/docs/examples/pdf-merge.js index d8cdcfcb..ebf2649b 100644 --- a/docs/examples/pdf-merge.js +++ b/docs/examples/pdf-merge.js @@ -54,14 +54,14 @@ function pdfmerge() { var srcDoc, dstDoc, i dstDoc = new PDFDocument() - for (i = 2; i < argv.length; ++i) { - srcDoc = new PDFDocument(argv[i]) + for (i = 1; i < scriptArgs.length; ++i) { + srcDoc = new PDFDocument(scriptArgs[i]) copyAllPages(dstDoc, srcDoc) } - dstDoc.save(argv[1], "compress") + dstDoc.save(scriptArgs[0], "compress") } -if (argv.length < 3) +if (scriptArgs.length < 2) print("usage: mutool run pdf-merge.js output.pdf input1.pdf input2.pdf ...") else pdfmerge() diff --git a/docs/examples/trace-device.js b/docs/examples/trace-device.js index 9d7d4373..d3ddec81 100644 --- a/docs/examples/trace-device.js +++ b/docs/examples/trace-device.js @@ -93,10 +93,10 @@ var traceDevice = { }, } -if (argv.length != 3) +if (scriptArgs.length != 2) print("usage: mutool run trace-device.js document.pdf pageNumber") else { - var doc = new Document(argv[1]); - var page = doc.loadPage(parseInt(argv[2])-1); + var doc = new Document(scriptArgs[0]); + var page = doc.loadPage(parseInt(scriptArgs[1])-1); page.run(traceDevice, Identity); } diff --git a/docs/manual-mutool-run.html b/docs/manual-mutool-run.html index 26964081..310c69cc 100644 --- a/docs/manual-mutool-run.html +++ b/docs/manual-mutool-run.html @@ -15,8 +15,9 @@

The 'mutool 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. -All of the MuPDF constructors and functions live in the global object, and the command line arguments are accessible -from the global 'argv' object. +All of the MuPDF constructors and functions live in the global object, and the +command line arguments are accessible from the global 'scriptArgs' object. +The name of the script is in the global 'scriptPath' variable.

 mutool run script.js [ arguments ... ]
-- 
cgit v1.2.3