Background
History
JavaScript was invented as part of the Netscape Navigator browser such that web pages could be more interactive. As lore goes, the first version was created in only 10 days! It has stood the test of time and remains as the cornerstone of web development. These days, JavaScript development for the web looks very different than it did nearly 30 years ago. There are numerous advancement such as single page application frameworks, package managers, bundlers, and more that has enabled teams of people to work on complex web applications.
However, PDF JavaScript development is not so different than the way development took place in the early internet. PDF JavaScript for the most part is embedded within indvidual PDF files, and as a developer, rather than pulling in many different pre-existing packages and using build systems, plain JavaScript will need to be written that targets a completely different object model than that of the web.
As the original stewards of the PDF specification, Adobe introduced JavaScript capabilities into Adobe Acrobat in support of interactive form fields. Revu has supported JavaScript since version 6.5 with expanded support in updated versions of Revu over time.
DOMs (Document Object Models)
The only similarity between web and PDF development, is that the core language is the same. Meaning that types such as strings, arrays, and numbers are applicable whether in the web or a PDF. However, the web and PDF have very different document object models. As such, it is imperative that when making internet searches for JavaScript assistance, that you understand when the results are referring to web development that may not be applicable for the PDF JavaScript you are developing.
A document object model connects the core language of JavaScript to the domain of the particular application hosting the script capability. For web, this domain is an HTML web page and its tree of elements. For PDF, the domain is the PDF document with its own collection of PDf specific elements, such as form fields, layers and more. This book documents the complete DOM of Revu as well as dives into using JavaScript in PDF files to make them more interactive for specific workflows.
Contexts
Another key difference between web development and PDF development is where you write your code. In web development, typically you would create a file with the .js extension that lives alongside your HTML file and is published as part of the web page. Addtionally, you would modify the .js file in the code/text editor of your choice.
PDF is different in that snippets of JavaScript are typically embedded throughout the PDF accessed in different areas within Revu directly.
In a later chapter we will go into detail of all the different contexts of which JavaScript can be run from within a PDF file. For now, let's dive straight to a Hello World example.