Monday, August 11, 2014

Dynamic pdf causing issues - unable to access form fields

I just figured out an issue that I don't think Gary ever got to the bottom of.  It all came down to the fact that not all pdf forms are created equal, and some of the forms we were using were getting saved in a different format that wasn't working with our code.  It would appear that pdf's can come in about 4 different formats.

From the adobe blog:

Flat PDF – A PDF with no XFA stream and no non-signature elements. Basically there are no fields in the document. It is important to note that a “Flat” PDF may still have some layers, such as the comment layer. In this case the flatness refers to the lack of data fields. 
Static PDF – A PDF which contains an XFA stream and the form layout does not change. Static forms may be interactive (a user can still fill in fields). If a dynamic XDP is rendered with LiveCycle Forms with the Render At Client option set to “No” then the resulting PDF is no longer dynamic – it is now static and behaves like any other static PDF.
Dynamic PDF – Dynamic PDFs allow the layout of the form to be altered either through user interaction or through script. An example is a form that adds subforms based on a user input. If a static XDP is rendered with LiveCycle Forms with the Render At Client option set to “Yes” then the resulting PDF is no longer static – it is now dynamic and behaves like any other dynamic PDF. 
Acroform – A non-XFA based PDF form, usually created directly in Adobe Acrobat (as opposed to using LiveCycle Designer).
When I tried running the following code
formApp = CreateObject("AFormAut.App")
acroForm = formApp.Fields
If the form was saved in Adobe LiveCycle as Static, acroForm would contain all of the fields from the form, however if it was saved as dynamic, no error was thrown, but acroForm would not contain any fields.  Both static and dynamic forms use XFA streams (Adobe's flavor of xml) to render the pages, but the underlying structure and the way the form is displayed can be dramatically changed in a dynamic form.  It would appear that my code was unable to access the fields, because the structure of the fields on a dynamic form can change after it is rendered.  A field that was on page 1 to start with could end up on page 10 after the client using the form made some selections that altered the form or even problematically before the form was first rendered.  

To fix my issue, I just went into Adobe Lifecycle and used the save as function to save the dynamic forms as static forms.

Thanks to the following links that helped me figure this issue out.

No comments:

Post a Comment