The Scripts the Document Registers by Name

Register scripts under names of your own, run by reading software when it opens the document and called by the actions of its fields.

Summary

A form that adds up its own lines, checks a date or fills in a total needs a few functions to do it. Rather than repeat them in every field, you write them once under a name, and every field and every button calls them. Reading software that runs scripts runs these as the document opens; a program that runs none shows the document all the same.

Technically

Written at the top level of a request, under "scripts"

scripts writes the /JavaScript name tree of the catalogue's /Names dictionary: one entry per name, each a script action carrying its source. The source is written as it is given: nothing here runs, checks or parses it. A second script under a name already given is refused.

Request Schema

  • scripts — array, optional, empty by default.
  • scripts[].name — string, required. The name the script is registered under.
  • scripts[].source — string, required. The script itself, written as it is given.

The first three parts of PDF/A refuse a document registering scripts, and a check of one of them names it; pdfa4 lets one through. An item or a field runs a script through the action {"script": …}.

A Whole Request That Creates a PDF

{
  "scripts": [
    {
      "name": "totals",
      "source": "function total(a, b) { return a + b; }"
    }
  ],
  "standard_fonts": [{ "name": "sans", "face": "helvetica" }],
  "items": [
    {
      "type": "text",
      "rect": { "llx": 60, "lly": 740, "urx": 535, "ury": 765 },
      "content": ["A form whose fields share one function"],
      "font": "sans",
      "font_size": 14
    }
  ]
}

The line that sends it, in three languages

Finding one's way through it

The Order One Field Leads to the Next What a Page Sets off as Reading Software Comes and Goes What the Document Runs as It Is Closed, Saved or Printed What the Document Says It Is Made Of The Clickable Contents Down the Side Landing Places That Have a Name Following an Article Column by Column How the Document Opens and Prints

Where to Go Next

Every JSON key of a request, in one page The other forty-one settings of a request

See the Prices See the Examples