Sunday, March 21, 2010    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Jul 2006 >>
S M T W T F S
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

Search

Categories
 • Acrobat (3) [RSS]
 • Adobe (90) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (66) [RSS]
 • AdobeMAX09 (39) [RSS]
 • AdobeMAX10 (1) [RSS]
 • AIR (219) [RSS]
 • Appearances (191) [RSS]
 • Books (72) [RSS]
 • CFEclipse (15) [RSS]
 • ColdFusion (1381) [RSS]
 • Data Services (34) [RSS]
 • Fish Tank (5) [RSS]
 • Flash (197) [RSS]
 • Flex (498) [RSS]
 • Home Automation (5) [RSS]
 • Jobs (116) [RSS]
 • JRun (14) [RSS]
 • Labs (43) [RSS]
 • LiveCycle (34) [RSS]
 • MAX (232) [RSS]
 • Mobile (120) [RSS]
 • Regular Expressions (17) [RSS]
 • RIA (21) [RSS]
 • SQL (40) [RSS]
 • Stuff (536) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (162) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • Mark Doherty
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
July 27, 2006

CF_PDFForm: Programmatically Set And Get PDF Form Fields

The ability to programmatically access and manipulate PDF forms from within ColdFusion has been requested since, well, since we first demonstrated PDF generation abilities in ColdFusion MX 7. At CFUNITED a few weeks ago, Jason Delmore (ColdFusion Product Manager) demonstrated a planned ColdFusion "Scorpio" tag named <cfpdfform> which he used to populate (pre-fill) and extract values from a PDF form.

Scorpio is scheduled to be released in 2007. So what to do if you need PDF form support in ColdFusion right now? Well, here's a solution:

Adobe has a Java API named XPAAJ (which stands for XML/PDF Access API for Java). The API can be used to:

  • Extract and insert PDF form field data.
  • Convert PDF documents to XDP format.
  • Access PDF metadata and file attachments.
  • Add, replace, and delete embedded data objects, file attachments, and annotations.
  • Obtain PDF file properties.
  • ... and more.

Until a few days ago the XPAAJ license restricted use of the API to customers with licensed copies of LiveCycle servers. But that license has been updated to include other Adobe servers, including ColdFusion. As such, if you have a licensed copy of ColdFusion you may register and download XPAAJ and use it with ColdFusion.

Of course, using XPAAJ from within CFML code requires writing ColdFusion Java code. And so, to make life easier for us CFers, I wrote a Custom tag named <cf_pdfform> which makes it really easy to get and set PDF form field values. Want to pre-fill a PDF form? You can use this code:

<!--- PDF form --->
<cfset pdfForm=ExpandPath("Grant Application.pdf")>
<!--- Output PDF name --->
<cfset pdfResult=ExpandPath("Grant Application Filled.pdf")>

<!--- Generate filled in form --->
<cf_pdfform action="set"
        form="#pdfForm#"
        destination="#pdfResult#">

<cf_pdfformparam name="ProjectTitle" value="My Project">
<cf_pdfformparam name="RequestNum" value="1234567890">
<cf_pdfformparam name="RequestTitle" value="Widget Study">
</cf_pdfform>

Extracting PDF form field values is just as easy:

<!--- Output PDF name --->
<cfset pdfResult=ExpandPath("Grant Application Filled.pdf")>

<!--- Get field data --->
<cf_pdfform action="get"
        form="#pdfResult#"
        result="fields">


<!--- Dump it --->
<cfdump var="#fields#">

<cf_pdfform> is not as powerful or capable as Scorpio's planned <cfpdfform> tag family, but it'll help you in the interim.

To use <cf_pdfform> you must download and install XPAAJ.jar from the LiveCycle Developer Center XPAAJ page (you will need to register and accept the license before doing so). XPAAJ comes with extensive documentation and examples (none of which are actually needed to use <cf_pdfform>, although if you want to use XPAAJ to do more, this is all of the documentation you'll need). Then you'll need the attached ZIP file (see the download link below) which contains the <cf_pdfform> Custom Tag, documentation, and a CFML example.

Enjoy!

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments

  © Copyright 1997-2009 Ben Forta, All Rights Reserved