Choose an example to view, copy, or download its script.
Available in pre-release 3.7.
Choose an example, or use the left and right arrow keys.
Load a PDF
Print the page count of a PDF.
- Input PDF (default:
<INPUT>)
// Info: Print the page count of a PDF.
// Arg: <INPUT> : Input PDF
var input = scriptArgs[0];
var doc = Document.openDocument(input);
print(doc.countPages());
Run a script #
To run an example in SumatraPDF, open a PDF, press
Ctrl + K, and choose
Run PDF Script…. Paste the script and set its arguments in the listed order.
Save any unsaved annotations before running a script that reads the PDF.Or download the script and run it from a command prompt:
sumatrapdf-tool.exe run script.js [arguments...]
Use
"" for an empty optional argument. Choose a different output
path from the input PDF; existing output files can be overwritten.The first examples are adapted from the
MuPDF JavaScript cookbook.
See sumatrapdf-tool run for command-line details and the
JavaScript API reference for classes and methods.