DEV Community

IDRSolutions
IDRSolutions

Posted on

How to draw PDF XFA Forms accurately (in your viewer)

Introduction

It is a bit of a complex task if any attempt is made to try and display XFA forms (by following the XFA specification) in a custom viewer rather than the Adobe life cycle. Either you are expected to have a similar functionality to the HTML parser, which should be intelligent enough to draw components recursively, or you should have a custom parser.

Structure of Subforms

Subforms in XFA may contain one or many subforms, and each of them may contain individual components that could be either containers (containing subforms, exclusion groups, area, subformset) or widgets (Rectangle, text, arc, input text, checkbox, choice-list and so on).

Handling Coordinates and Dimensions

Every subformโ€™s x,y coordinates depend on previous and parent elements of it; its height depends on the height and width of the child elements if the H attribute or min H attribute is not specified.

In such a complex situation, the form height and x,y coordinates should be in memory or should be injected as an attribute in order to render them accurately (in my personal opinion, injecting data as an attribute consume much less memory).

Influence of Datasets

Datasets also have a major influence on the way the form is rendered, because form occurrences (number of forms) have to be multiplied based on bind data (be aware that bind names play a major role rather than the typical name attribute of the subform node).

Page Breaks and Content Overflow

Forms do have page breaks that render the form and its components on different pages. In addition to that, components of a single form can be split into multiple pages if their x,y location exceeds the allowed height of the content area of the PageArea element.

Recommended Handling Approach

One of the recommended ways of handling such a scenario described above is to draw the form coordination in memory or as attributes and splitting them later based on page breaks, data sets and content area overflow. Margins (left, right, bottom and top) also need to be considered on the stage of rendering.

Layout Considerations

Possible subform layouts such as Positioned, Top to bottom. Left to right, right to left, table and row have to be considered in finding the relevant heights of the given subform. The calculation may vary from one to another.

Dynamic XFA Forms and JavaScript

Dynamic XFA forms contain JavaScript (a real beast in XFA layout) that determines visibility and total occurrence of individual forms.

Top comments (0)