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">)
</cfquery>
<!--- 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')>
</cfpdfform>
<!--- flatten --->
<cfpdf action="write" source="figbucks#qget.currentrow#.pdf" destination="figbucks_flat_#qget.currentrow#.pdf" flatten="yes" overwrite="true">
</cfpdf>
</cfloop>
<!---- merge --->
<cfpdf action="merge" destination="coupons.pdf" overwrite="yes">
<cfloop from="1" to="#qget.recordcount#" index="i">
<cfpdfparam source="figbucks_flat_#i#.pdf">
</cfloop>
</cfpdf>
<!--- transmit --->
<cfcontent file="#expandpath('.')#\coupons.pdf">
</cflock>
Tuesday, June 9, 2009
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment