JavaScript in PDF to HTML5 Conversion: Formatting & The Field Object

It has been a while since the previous article on our work with converting JavaScript from PDF documents to work with extracted HTML5 from our converter so if you didn’t catch the start of them you can view it here.

In my previous post I spoke about the Event object and mentioned in passing the Field object. When writing that post we were just using the built into HTML/JavaScript input and form elements/object to display and store the results of events which worked up until a point but prevented us from completely emulating how PDF forms work.

Specifically this prevented us from emulating how fields were formatted upon leaving them. To rectify this we implemented our own version of the Field object described within the Adobe’s API and tied it into the form objects currently used. This means that now upon leaving a form field it is not only calculated correctly but also formatted correctly so.

Opening this example file in Adobe you will see that upon changing the inputs they are reformatted in this case they are forced to have 2 decimal points (regardless of the fact that the number you place within them isn’t a decimal or that the number has more digits after the first 2 decimal places). And now upon converting this file we get similar behaviour.

For those interested, this specific behaviour is caused by the embedded JavaScript in a field objects Format object:

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

We’ve also implemented the behaviour for pressing Return/Enter within a field. Originally this had been overlooked.

We are well on our way to getting all the features of the JavaScript embedded into PDFs, are there any particularly interesting interactive PDFs you’d like to see converter?

The following two tabs change content below.
Lyndon is a Developer at IDR Solutions. He currently focuses mostly on the JavaScript in the Viewer and PDF to HTML5 Converter and also the Android PDF Viewer. He gave a short talk at the GlassFish UnConference before JavaOne 2012. Outside of IDR Solutions he has a keen interest in AI and Games Programming and runs a blog that he periodically updates.

Related Posts:

lyndon

About Lyndon Armitage

Lyndon is a Developer at IDR Solutions. He currently focuses mostly on the JavaScript in the Viewer and PDF to HTML5 Converter and also the Android PDF Viewer. He gave a short talk at the GlassFish UnConference before JavaOne 2012. Outside of IDR Solutions 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 *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>