KiteScriptEngine

A JavaScript engine for the scripts that documents carry: PDF JavaScript actions and document-level scripts today, EPUB scripting later.

KitePDF ships no engine of its own. Add kitepdf-javascript for one that runs on KiteJS, or implement this interface over another engine. Code that only needs to run scripts should take this interface, so it never depends on an engine directly.

Functions

Link copied to clipboard
expect abstract fun close()
Link copied to clipboard
abstract fun defineFunction(name: String, function: (List<Any?>) -> Any?)

Makes function callable from scripts under name, which may be a dotted path such as app.alert: missing objects on the way are created. Arguments arrive as Kotlin values (String, Double, Boolean, List, Map or null), and the return value goes back the same way.

Link copied to clipboard
abstract fun defineValue(name: String, value: Any?)

Sets name, a plain or dotted path, to value: a string, number, boolean, list, map or null.

Link copied to clipboard
abstract fun evaluate(source: String, name: String = "<script>"): String?

Runs source and returns its result as text, or null when the result is undefined or null. name labels the script in error messages.