» Fig Leaf Software Home

We've Got You Covered.

Tuesday, June 9, 2009

Populating and Merging PDF Forms with ColdFusion 8

Today I developed a system for our training web site (http://training.figleaf.com) that would allow us to easily generate coupons. These coupons consisted of three fields -- a label, a validation code, and an expiration date. Because I've never worked on a project that I couldn't make more complicated, I decided to generate the coupons as a merged PDF -- thereby allowing us much more flexibility in the design of the document.

So here's the rub -- ColdFusion 8 allows you to populate forms that are developed using either Adobe Acrobat ("AcroForms") or Adobe LiveCycle Designer.

Unfortunately, you can only merge populated Acroforms -- NOT LC Designer Forms.

Why is this the case? Well, my guess is that it has something to do with...(wait for it....) LICENSING

Populating LC forms from a server requires the use of Adobe Output Server ES -- which will set you back quite a bit of money....whereas populating AcroForms from CF is essentially free.

Here's the basic algorithm. Note that the generated acroforms had to be "flattened" before they could be merged.

<cfquery name="qGet" datasource="foobar">
select *
from couponinstance,coupon
where couponinstance.couponid = coupon.couponid
and couponinstance.couponinstanceid in (<cfqueryparam cfsqltype="cf_sql_numeric" value="#url.couponinstanceid#" list="yes">)

<!--- single thread for file assembly --->
<cflock type="exclusive" name="generatecoupons" timeout="60">
<cfloop query="qget">
<!--- populate form --->
<cfpdfform action="populate" source="figbucks.pdf" destination="figbucks#qget.currentrow#.pdf" overwrite="yes">

<cfpdfformparam name="id" value="#qget.couponsn#">
<cfpdfformparam name="label" value="#qget.couponlabel#">
<cfpdfformparam name="expdate" value="#dateformat(qget.couponexpirationdate,'mm/dd/yyyy')>


<!--- flatten --->
<cfpdf action="write" source="figbucks#qget.currentrow#.pdf" destination="figbucks_flat_#qget.currentrow#.pdf" flatten="yes" overwrite="true">

<!---- merge --->
<cfpdf action="merge" destination="coupons.pdf" overwrite="yes">
<cfloop from="1" to="#qget.recordcount#" index="i">
<cfpdfparam source="figbucks_flat_#i#.pdf">

<!--- transmit --->
<cfcontent file="#expandpath('.')#\coupons.pdf">


No comments:

Post a Comment

About Us

Fig Leaf Software is an award-winning team of imaginative designers, innovative developers, experienced instructors, and insightful strategists.

For over 20 years, we’ve helped a diverse range of clients...

Read More

Contact Us


Fig Leaf Software

1400 16th Street NW
Suite 450
Washington, DC 20036