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.

JavaScript and Jpedal 5

1 min read

In Part 4 of a series of articles regarding the JPedal Version 5.X update we explore the big changes that this update will bring.

JavaScript in PDF files

Did you know that PDF files can contain JavaScript? It can be used to validate form values and also to provide sophisticated user interaction. We have even see a Hangman game written as a PDF file with JavaScript. So JavaScript support has been high on our list of features to improve.

You may of seen some of our blog posts on JavaScript support in the past. Below is what we have been up to recently and in preparation for version 5 of our PDF library and viewer.

Improvements in HTML Conversion

In our latest version we now support even more actions and JavaScript within our converted files. A few of them include:

  • All internal and external links should be correctly converted.
  • Embedded audio will work.
  • Printing buttons.
  • First, Last, Next and Previous page links will link correctly.

Support for JavaScript in forms has also been improved. One such improvement is that we now support date and time formatting within text boxes in the way you’d expect.

Nashorn and Rhino

With the announcement of Nashorn as a replacement for Rhino in the JDK it felt like time for us to revisit our viewers use of Rhino to parse embedded JavaScript within PDF files and forms and to get it ready to take advantages of the improvements featured in Nashorn.

One of the main reasons we are making our viewer compatible with Nashorn is to take advantage of it’s speed; according to Jim Laskey at Oracle it is three to five times faster than Rhino and a lot smaller to boot!

After getting Nashorn working under Java 7 so we could have a look at it we actually began recoding our viewers JavaScript Parser. This is because we originally made it using Rhino’s own library and API and Nashorn makes use of the Java Scripting API, JSR-223.

JSR-223 was designed to make it easy to use scripting engines that run on the JVM, achieving this by having a consistent API. An API that differs slightly to Rhino’s own.

So what will this recode mean when done? Well because Rhino is already packaged with the current version of the JDK using the same API it means that, when completed, regardless of the JDK you are running on you should see improvements and eventually when Java 8 is released (or a version of Nashorn is made available for Java 7) the viewer’s JavaScript will run even faster!

Support for Nashorn will be available in future versions of Jpedal 5 so be on the look out for an improvement when your viewing forms in our viewer!

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the Blog RSS.

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.

Making a Simple Basecamp Chatbot with NodeJS

Creating a chatbot is a fun way to integrate external tool functionality within Basecamp. I recently created one to call the Bitbucket API, allowing...
Leon Atherton
1 min read

Three things I learned at Devoxx

Throughout Devoxx Belgium, I attended many talks on an array of topics. Writing about everything I learned would produce a novel rather than a...
Ovidijus Okinskas
3 min read

Leave a Reply

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