Documentation for using JavaScript code inside a PDF file

112,579

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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.

Share:
112,579

Related videos on Youtube

Sam
Author by

Sam

Updated on July 05, 2022

Comments

  • Sam
    Sam almost 2 years

    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.

    • kelalaka
      kelalaka over 3 years
    • FluidCode
      FluidCode over 2 years
      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.
  • Sam
    Sam over 12 years
    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.
  • Sam
    Sam over 11 years
    Thank you for your answer. I'll look for the book. I think seeing examples in context would be useful.
  • knb
    knb over 11 years
    @Sam updated my answer for 1 more thing that I remembered just now.
  • Max Wyss
    Max Wyss about 9 years
    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.
  • jss
    jss almost 9 years
    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 Adobe
  • Bobrovsky
    Bobrovsky almost 9 years
    @jss Did you check the Acrobat SDK? Does it ship with a more modern JavaScript-in-PDF reference?
  • jss
    jss almost 9 years
    @Bobrovsky 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.
  • jss
    jss almost 9 years
    Link to SDK download that includes Javascript reference adobe.com/devnet/acrobat.html
  • Code Jockey
    Code Jockey about 7 years
    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...
  • Kiril
    Kiril over 2 years
    Not anymore, seems to be down