Lyndon Armitage Lyndon is a general Developer. He has a keen interest in AI and Games Programming and runs a blog that he periodically updates.

Do you need to display PDF Forms in a Browser?

Find out how FormVu can convert PDF Forms into HTML5

JavaScript in PDF to HTML5 Conversion: Introduction

1 min read

Recently we have begun development on converting the JavaScript contained within PDFs to JavaScript that can be used by any browser browsing the HTML5 files made by our converter. This is by far no small task and no other PDF to HTML converters I have seen have actually tried to implement this.

The preparation for doing this involved a lot of searching, head scratching and understanding. Firstly if you do a search for the keywords JavaScript and PDF you will come across a link to Adobe’s JavaScript for Acrobat API Reference; a document spanning 769 pages that describes all the objects, and their methods, that are used when adding JavaScript inside a PDF file. But also, if you actually look within a PDF that contains JavaScript you will find that Acrobat implements some of its own scripts and methods that are described in Adobe’s Acrobat Forms API Reference and, up until Acrobat 7.0, were included as .js files within the install directory of Acrobat for those curious. And don’t forget Adobes own PDF Reference that as of writing spans 978 pages (that’s a lot of reading!) although only a limited part within it about how forms are treated, and gives you crucial hints on how the JavaScript should work within viewers.

Extracting the embedded JavaScript itself is simple as it is just an object within the PDF file that is linked to a Field object. However each Field can have several different bits of JavaScript embedded within it, each being run upon different events. For instance here is some JavaScript that is run upon a keystroke within a specific field:

AFNumber_Keystroke(2, 0, 0, 0, '', false);

(That’s one of Acrobat’s own methods I mentioned earlier.)

Using existing features in our library it’s easy to determine which events specific bits of JavaScript belong to within the PDF since they are bound to specific keys (this is where the PDF Reference comes in handy). However, the hard part is mapping them onto an event within HTML5/JavaScript, implementing the needed objects correctly and also understanding how these events should be called within a PDF.

We will be keeping you posted on our progress!

Have you got any interesting PDFs with JavaScript in them that might work well as HTML5 files?



FormVu allows you to

Use PDF Forms in the Web Browser
Integrate PDF Forms into Web Apps
Parse PDF forms as HTML5
Lyndon Armitage Lyndon is a general Developer. He has a keen interest in AI and Games Programming and runs a blog that he periodically updates.

How to insert an image into a PDF

Recently, we released JPedal 2023.07 which contains the ability to insert images into PDF files. All you need is a copy of JPedal, a...
Jacob Collins
18 sec read