Documentation for using JavaScript code inside a PDF file [closed]
Asked Answered
D

5

86

Where can I find documentation on running JavaScript code inside a PDF?

I've never added a JavaScript action inside a PDF document. However, I've done quite a bit of web development using JavaScript. I have a few questions to whoever has any familiarity with JavaScript inside a PDF document.

NitroPDF and Adobe Acrobat definitely support JavaScript in PDF files. Is there a standard on various objects that exist and functions to manipulate a PDF file via JavaScript? Everything I've found so far has been from Adobe. Anywhere else seems to reference Adobe's documentation. Is there a standard out there, or is Adobe just the "de Facto" standard?

Also, Do all PDF viewers support JavaScript actions?

The best documentation on using JavaScript inside a PDF document that I could find was from Adobe - Adobe :: Acrobat JavaScript Scripting Guide.

NitroPDF has this link - NitroPDF :: JavaScript in PDF Files, but it basically just says it supports what Adobe has.

I also found this link from Scribus - Scribus :: How to enhance your PDF forms with JavaScript, but this only includes a few small snippets of code. Nothing super useful.

Adobe has documentation on how you can set breakpoints, etc... for JavaScript using their IDE. Is it possible to run JavaScript in a PDF file using another IDE and have breakpoints, etc...? It would be awesome to find something as cool as Firebug.

Note:

Please do not answer how to manipulate a PDF that is loaded in a web browser. The question is about running JavaScript from within a PDF document. I'm trying to explore the possibilities available via executing JavaScript in the PDF document. Specifically I may use functions from quickpdflibrary to add JavaScript functionality to existing documents.

Another useful link is Developing with Acrobat JavaScript. Apparently JavaScript code in PDFs is frequently called AcroJS or Acrobat JavaScript.

Disloyalty answered 9/2, 2012 at 22:26 Comment(2)
This can be used for tracking!Fillbert
Putting together PDF and javascript functionalities is the classic recipe to make the usual can of worms. We lost the count of the number of viruses spread via infected documents a long time ago.Backhouse
C
45

Probably you are looking for JavaScript™ for Acrobat® API Reference.

This reference should be the most complete. But, as @Orbling said, not all PDF viewers might support all of the API.

EDIT:

It turns out there are newer versions of the reference in Acrobat SDK (thanks to @jss).

Acrobat Developer Center contains links to different versions of documentation. Current version of JavaScript reference from Acrobat DC SDK is available there too.

Christopher answered 10/2, 2012 at 13:15 Comment(5)
Wow... That API Reference is sooooo much better than what I found. Thank you. Too bad there isn't a standard out there though :( I may just need to try some javascript out and see through trial / error which support javascript.Disloyalty
As far as I remember reading, some core (Acrobat) JavaScript will become part of the next version of ISO 32000… it is then, of course, the decision of the PDF viewer makers whether they would want to be ISO 32000 compliant. FWIW, the "better" PDF viewer makers which do support some JavaScript do have an overview of what they support in their support pages, otherwise, you can ask their support for this information.Leningrad
A heads up for others, this reference has not been updated since 2007. Max Wyss's answer is the most up to date documentation provided by AdobeEverlasting
@Everlasting Did you check the Acrobat SDK? Does it ship with a more modern JavaScript-in-PDF reference?Christopher
@Christopher Yeah it does. They do a new Javascript reference with each version of Acrobat, the most recent update came a couple months ago. I think version 8.1 was the last Javascript reference Adobe provided that wasn't bundled with the entire SDK package, and for whatever reason they haven't taken it down despite the fact that they stopped supporting Acrobat 8 in 2012.Everlasting
L
6

The comprehensive place for Acrobat JavaScript documentation is the Acrobat SDK, which can be downloaded from the Adobe website. In the Documentation section, you will find all the material needed to work with Acrobat JavaScript.

To complete the documentation you may in addition get the specification of the JavaScript Core. My book of choice for that is "JavaScript, the Definitive Guide" by David Flanagan, published by O'Reilly.

Leningrad answered 30/3, 2014 at 12:27 Comment(2)
Link to SDK download that includes Javascript reference adobe.com/devnet/acrobat.htmlEverlasting
I guess..... leave it to Adobe to put all their JS documentation in a place that Google can't help you search? ... I am so confused right now...Shamefaced
L
5

I'm pretty sure it's an Adobe standard, bearing in mind the whole PDF standard is theirs to begin with; despite being open now.

My guess would be no for all PDF viewers supporting it, as some definitely will not have a JS engine. I doubt you can rely on full support outside the most recent versions of Acrobat (Reader). So I guess it depends on how you imagine it being used, if mainly via a browser display, then the majority of the market is catered for by Acrobat (Reader) and Chrome's built-in viewer - dare say there is documentation on whether Chrome's PDF viewer supports JS fully.

Latium answered 9/2, 2012 at 22:33 Comment(0)
M
2

Look for books by Ted Padova. Over the years, he has written a series of books called The Acrobat PDF {5,6,7,8,9...} Bible. They contain chapter(s) on JavaScript in PDF files. They are not as comprehensive as the reference documentation listed here, but in the books there are some realistic use-cases discussed in context.

There was also a talk on hacking PDF files by a computer scientist, given at a conference in 2010. The link on the talk's announcement-page to the slides is dead, but Google is your friend-. The talk is not exclusively on JavaScript, though. YouTube video - JavaScript starts at 06:00.

Milter answered 14/12, 2012 at 12:36 Comment(1)
Thank you for your answer. I'll look for the book. I think seeing examples in context would be useful.Disloyalty
R
1

Here you can find "Adobe Acrobat Forms JavaScript Object Specification Version 4.0"

Revised: January 27, 1999

It’s very old, but it is still useful.

Rubiaceous answered 26/11, 2013 at 19:51 Comment(1)
Not anymore, seems to be downTranscurrent

© 2022 - 2024 — McMap. All rights reserved.