HTML to PDF converter for Java and .NET

HOME   FEATURES   PRODUCTS   DOWNLOADS   BUY NOW!   SUPPORT
<< back

PD4ML: PDF Action Handlers

PDF file format allows to enhance a PDF document with Acrobat JavaScript for processing within a single document, processing for a given page, processing for a single form field etc.

With PD4ML a typical JavaScript scenarios are to force a print dialog popup or to fill/update some PDF form fields.

PD4ML supports an assigning of JavaScript handlers to the following action types:

  • "OpenAction" (document open),
  • "DC" (document close),
  • "WS" (will save),
  • "DS" (did save),
  • "WP" (will print), 
  • "DP" (did print)

using void addDocumentActionHandler(String actionType, String javaScript) PD4ML API call.

Simplest case. Set zoom factor to 600% by a document opening:

pd4ml.addDocumentActionHandler("OpenAction", "this.zoom = 600;");

Also an update of a PDF form field is not tricky. Let's say there is an HTML form field in a source document:

...
<input name=i1 type=text style="border: none"> 
...
The following Java code forces PD4ML to generate PDF form and defines a JavaScript, which sets the field value to the current date every time the PDF is opened.
...
pd4ml.generatePdfForms(true, null); 
pd4ml.addDocumentActionHandler("OpenAction", "this.getField('i1').value = new Date().toDateString();");
...
A print dialog popup code sample can be found by the link.

Note: PDF/A specification does not permit JavaScript handler definition, so in PDF/A generation mode pd4ml.addDocumentActionHandler() takes no effect.

Useful links:

Acrobat JavaScript Scripting Reference
Acrobat JavaScript Scripting Guide

 

 

Copyright ©2004-17 zefer|org. All rights reserved. Bookmark and Share