Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

PDF to html5 conversion – Forms and Javascript

58 sec read

In a PDF file it is possible to attach Javascript to a PDF form. This has many uses including validation, formatting or popping up a message. I have been looking at passing this through for our PDF to HTML5 conversion and this little example shows nicely some of the issues. It is easiest to follow in the raw PDF data so here is the data…

I have a PDF file with a text field (object 1139). The /AA key indicates a dictionary with a /Fo action. This is stored in object 1141.

1139 0 objTx/Subtype/Widget/P 7 0 R/T(AktionJavaScirptAlert)/AA<>/DA(/Helv 0 Tf 0 g)/MK<<>>>>

This has a fragment of Javascript attached to an action.

1141 0 obj<Hallo”\)\r\n})>>

HTML5 allows us to add Javascript actions to the Form fields so all we need is to extract the Javascript and attach it to the Form component. Piece of cake? Not quite so easy…

Adobe’s dialect of Javascript is not entirely the same or compliant with the Browsers Javascript engine. Here is what I need to convert it into to work in HTML5. The object app. is used by Adobe but redundant in HTML and the double quotes need to become single quotes.

<input type=”text” tabindex=”2″ id=”AktionJavaScirptAlert” value=”” pdfFieldName=”AktionJavaScirptAlert” onClick=”{
}” />

Once done it works as expected.

So some interesting debugging lined up for the next few weeks. It should make for some interesting blog articles…

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


Converting PDF/ Office Documents to HTML?

Convert PDF to HTML Find out why our customers use BuildVu for HTML conversion

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Dawscon 2020 Software Conference in Pictures

The latest Dawscon software conference took place today at Dawson College, Montreal. Attendance was free and there were 2 tracks with topics including JavaScript,...
Mark Stephens
17 sec read

2 Replies to “PDF to html5 conversion – Forms and Javascript”

  1. This is an interesting idea, but it will work only in the most basic cases: There is a big difference between Acrobat JavaScript and browser based JavaScript. Both share the same core language, so anything that just uses the core language should work, but the really useful part of the JavaScript implementation – for both the browser and Acrobat – comes from the domain specific parts of the JavaScript implementation. In the browser, you are dealing with web sites, HTML and communication with a server and more, whereas in Acrobat you are dealing with PDF specific contents (e.g. forms objects, annotations, optional content…), animations in PDFs, signatures, and a whole bunch of other stuff. Even a simple form field validation will very likely use some of the Acrobat specific validation functions that you wont have access to in HTML5.

    I would love to hear your take on this, and if you are planning on converting some of the Acrobat specific JavaScript functions. I’m pretty sure that a lot could be done by providing some library functions that would mimic the Acrobat specific DOM.

  2. There will be some things that work (control on Layers) but the idea is to get as much as possible working such as the AF formatting and validating commands.

Leave a Reply

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

IDRsolutions Ltd 2021. All rights reserved.