Contexts

JavaScript in Revu executes from three distinct contexts, each with its own purpose and scope:

  • Event-level scripts: Code that runs in response to user actions

  • Document-level scripts: Code that loads when a PDF opens

  • Folder-level scripts: Code stored externally that's available to all PDFs

Understanding where to place your code and what each context can access is fundamental to PDF scripting in Revu.

Context interaction

The three contexts work together to create complete solutions:

Copy
// Folder-level: Define utility
function calculateInterest(principal, rate, time) {
    return principal * Math.pow(1 + rate, time)
}

// Document-level: Add document-specific logic
var defaultRate = 0.05

function getLocalPayment() {
    var amount = this.getField("Amount").value
    return calculateInterest(amount, defaultRate, 5)
}

// Event-level: Use both in response to user action
var payment = getLocalPayment()
this.getField("Result").value = payment

Loading order

  1. Folder-level scripts load when Revu starts.

  2. Document-level scripts load when a PDF opens.

  3. Event-level scripts run when triggered.

This means folder functions are always available, document functions are available after the PDF loads, and event scripts can use both.

Quick reference

Where to place code:

  • Folder-level: Shared utilities across multiple PDFs

  • Document-level: PDF-specific functions and initialization

  • Event-level: User interaction responses

How 'this' works:

  • Folder-level: this is undefined

  • Document-level: this is the Doc object

  • Event-level: this is the Doc object

Moving forward

Understanding these three contexts provides the framework for JavaScript in Revu. The next section explores security.

Resources

Revu 21

Revu JavaScript

JavaScript

Understand where to place your JavaScript code and what each context can access.