PDF XFA Data Binding and Data Access

In this article I demonstrates some tips and techniques that can be followed while trying to map PDF XFA data to a XFA template.

As you may know, XFA datasets and XFA templates play major roles in rendering components in  a viewer. You can find more information about how to access a XFA dataset or XFA template using JPedal library at http://www.idrsolutions.com/how-to-access-pdf-forms#xfa

If a data map has the same number of template form elements then using XML dataset will be helpful, however if there is a mismatch (especially in quantity in dynamic forms) then we have to rename the xml data elements or template elements to match correctly.

Let us consider this example dataset and template

Dataset:

<Team>
<Employee>
<Name>John</Name>
<Address>25 abc road, AB1234</Address>
</Employee>
</Team>

Template:

<subform name=’Team’>
<subform name=’Employee’>
<field name=’Name’></field>
<field name=’Address’></field>
subform>
subform>

above the xml code defines static subform and simple data set; so we can match the data as it is defined in template.

Example 1 : [add another static field]

let us add another address to the template with the same field name.

<subform name=’Team’>
<subform name=’Employee’>
<field name=’Name’></field>
<field name=’Address’></field>
<field name=’Address’></field>
subform>
</subform>

at this point we have to rename similar name fields to map the data correctly. so rename displays as below with any different attribute

<field name=’Address’ yourAtrName=’Address[0]‘></field>
<field name=’Address’ yourAtrName=’Address[1]‘></field>

Note: (if you like you can rename the whole xml dataset and tempate to [] array  format to match correctly)

Example 2 : [handle dynamic forms]

The occurrence limits control how many times they are copied into the Form DOM during a merge operation; any subforms becomes dynamic if max attribute of occur element is not 1. So in above example let us make the maximum employees to unlimited occurrence using -1.

<subform name=’Employee’>
<occur max=”-1″/>

and we insert one more employee detail to the dataset and we insert naming attribute as array to differentiate employee1 from employee2

<Team>
<Employee yourAtrName=’Employee[0]‘>
<Name>John</Name>
<Address>25 abc road, AB1234</Address>

28 bbc road, BB1234

</Employee>
<Employee yourAtrName=’Employee[1]‘>
<Name>david</Name>
<Address>32 xyz road, XY1234</Address>
</Employee>
</Team>

while rendering template we could either clone the dynamic node as per data set occurrence and rename as array or we could process it in memory during data binding process.

Example 3: handling transparent forms

There is a possibility that a template can consist of subform which has no attribute “name”. During the process we have to ignore the data binding or attribute naming for such elements.

 <subform h=’11pt’ w=’33pt’>  //subform has no name attribute so it is transparent

Example 4: do not populate the data to fields or subforms those data bind match is none

finally we have to ignore elements in data binding process that contain no data bind match values

i.e. <subform> <bind match=”none”/> </subform>

I hope that you will find this information useful; if you are attempting to match the XFA data to template.

This post is part of our “XFA Articles Index” in these articles, we aim to help you understand XFA.

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 (TwitterFacebook and Google+) or the Blog RSS.

Ebook Page Link

The following two tabs change content below.

suda

Java EE developer at IDRSolutions
Suda is the Senior Java EE Developer at IDR Solutions, and specialises in XFA, Fonts, True-Type Fonts, application servers and conversions. He is a keen science-fiction fan in his spare time.

Related Posts:

suda

About suda

Suda is the Senior Java EE Developer at IDR Solutions, and specialises in XFA, Fonts, True-Type Fonts, application servers and conversions. He is a keen science-fiction fan in his spare time.

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>