JavaScript Support

The PDF Specification includes JavaScript support, based on JavaScript version 1.5 of ISO-16262 (formerly known as ECMAScript). The iOS PDF framework uses Apple's JavaScriptCore to support some of these JavaScript features.

PDF JavaScript support for other platforms, such as Android, Web or Windows are coming later in 2018.


There are many places in a PDF where JavaScript can be used:

  • Document Level Scripts (executed when the document JavaScript Runtime initializes)
  • PSPDFJavaScriptAction can be set anywhere where actions are set (any annotation or form element)

Since actions can be attached to any interactive element, JavaScript can be very ubiquitous. Calculating and formatting numbers in PDF Forms is one of the largest use cases for JavaScript support.

Note: When processing or modifying a document, ensure to use at least PSPDFKit 7.0.3 for iOS, to ensure that document-wide JavaScript entries are preserved.

Disable JavaScript

JavaScript can be disabled per document, via following call. Set this before the document is displayed.

document.javaScriptEnabled = false
document.javaScriptEnabled = NO;

Supported Features

PSPDFKit for iOS has basic support for the most common JavaScript features, such as:

  • alert
  • pageNum
  • numFields
  • getField
  • getNthFieldName
  • print
  • mailDoc
  • resetForm
  • alert (Basic alert, no parameters)
  • buttonImportIcon
  • launchURL

Furthermore, most color and console features are present, and various formatting options:

  • AFNumber_Format, AFMergeChange, AFNumber_Keystroke, AFNumber_Format, AFMakeNumber, AFDate_FormatEx, AFParseDateOrder, AFParseDateEx, AFDate_KeystrokeEx, AFParseTime, AFTime_Keystroke, AFTime_Format, AFTime_FormatEx, AFPercent_Format, AFSpecial_Keystroke, AFSpecial_Format, AFSimple, AFSimpleInit, AFSimple_Calculate.

JavaScript support is an experimental feature and methods might be incomplete or return unexpected results. You are advised to test your JavaScript-enabled documents thoroughly. This is not an officially supported feature, but please ping us if you have a document that isn't quite working, and we can see what we can do.


To see all JavaScript that is used in a Document, open Adobe Acrobat, Prepare Form, click the small down-arrow on the sidebar, All JavaScripts, and a window open that shows all JavaScript used on a certain page.

Learn More