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.

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?

This post is part of our “HTML5 Article index” in these articles, we aim to help you understand the world of HTML5.

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2019. All rights reserved.