Related topics:


Tutorial Videos

Tutorial videos are available here.

Knowledge Base

Visit our User Forum for discussions & solutions

Using Scripts in PDF Form fields

Using scripts when filling PDF forms need to be done in a certain way


When you are defining a PDF form field map in the Prepare PDF Form UI, you can specify that the source for a particular PDF field is either a data element, or a script.

If one or more scripts are specified, then the scripts need to be defined in a place that the MergePDFForm function knows about. And the way that the MergePDFForm works is that, if it finds the use of a script in the PDF field map, then it searches for a script definition.




Suppose the PDF form itself is called “ABC-File.pdf”, then MergePDFForm will look (in the same folder as the PDF form) for an XpressDox template called “ABC-File.scripts.xdtpx”. If that file does not exist, then it will search for a template called “PDFScripts.xdtpx”.

This means that if you have a number of PDF forms that use the same scripts, then you can use the PDFScripts.xdtpx template instead of making a .scripts.xdtpx for each PDF form.

The scripts template does not need to contain the scripts themselves, but can reference another scripts template that you have. This is done in the normal way, using the IncludeTemplate command (or the IncludeCodeTemplate command).



Scripts as Functions

When including a script in a PDF Form mapping, the syntax for invoking the script must be of the form of a “script as a function”. In other words, if a script is defined as

«Script(Beneficiary)»«SuffixWith(BeneficiaryTitle,' ')»«BeneficiaryLastName»«ScriptEnd()»

In the PDF mapping you would invoke this script, not as UseScript(Beneficiary), but as


Then, of course, if you try that, you will get a message from XpressDox saying words to the effect that when you use a script “as a function” then the contents of the script should be exactly one fillpoint. There are a number of ways of achieving this, but here is a straightforward example of how to treat the above script definition:

«Script(Beneficiary)»«concat(SuffixWith(BeneficiaryTitle,' '),BeneficiaryLastName)»«ScriptEnd()»

A very useful side effect of this feature is that you can use, not only scripts, but XPATH expressions, in the PDF field map. So that if you need, for example, the month of signature in a PDF form field, instead of setting a data element to the month and then defining that data element in the field map, just put FormatDate(DateOfSignature,’MMMM’) into the field map.

These two features are available with version 11.4.0, and so you would need to be licensed for XpressDox version 10.5 or later to make use of them.