Fragmented Thought

Prefilling Adobe LiveCycle PDF Forms with ColdFusion

By

Published:

Lance Gliser

Heads up! This content is more than six months old. Take some time to verify everything still works as expected.

So, the documentation is a bit lacking on coldfusion 8's docs about prefilling in LiveCycle forms. They suggest that you should "read in the structure of the document, then dump it back out to identify what fields are available." However, it doesn't quite work like that.

Adobe LiveCycle can put multiple forms in a pdf, sure. And that's well documented. What's missing is that each form will have multiple pages under it.

If you try to cfpdfformparam without knowing the correct page, you're bugged. And you won't even get a reason why you're buggered. Do not trust dumping the output of the pdf read. It can be useful to loop over, detecting if you have an acrobat form (no structures) or a LiveCycle form (structures), but it doesn't begin to cover what you need. You will need to open the pdf in LiveCycle, and inspect the form hierarchy window.

In case you need it...

<!--- Get pdf data to check for LiveCycle or Acrobat Form ---> <cftry> <cfpdfform source="#source#" result="pdfForm" action="read"/> <cfcatch> <p>The pdf is not interactive. No form fields could be found.</p> <cfabort> </cfcatch> </cftry> <cfpdfform action="populate" source="#source#" destination="" overwrite="true" overwriteData="true"> <!--- If created in Adobe LiveCyle, you will need to include cfpdfsubform tags to account for the multiple possible subforms ---> <cfif structCount(pdfForm) gt 0> <cfpdfsubform name="#formName#"> <cfpdfsubform name="#pageName#"><!--- Note that it is usually not a number, instead it's "page1" ---> <cfpdfformparam name="field" value="#value#"> ... </cfpdfsubform> </cfpdfsubform> <cfelse> <cfpdfformparam name="field" value="#value#"> </cfif> </cfpdfform> <cfpdf action="write" source="" destination="" flatten="yes" overwrite="true">

An interesting side effect of LiveCycle vs Acrobat created Pdfs:

You technically can output to a LiveCycle without defining the form and page. However, you're limited to only one field. The name doesn't seem to matter, just whatever is the last field is the one that is output.