Thursday, March 28, 2024

ColdFusion for the Web Developer, Part 2

PDF Manipulation

Seeing as ColdFusion is an Adobe product, it’s safe to assume that there are features for working with PDFs. ColdFusion 7 introduced the <cfdocument> tag that can be used to generate PDF documents from HTML. ColdFusion 8 added the <cfpdf> tag that can be used to manipulate existing PDF documents.


You may recall that ColdFusion is a Java application. Coincidently, LiveCycle PDF
Generator, Adobe’s enterprise tool for PDF manipulation, is a Java application too. As of version 8, ColdFusion includes a subset of LiveCycle PDF Generator. This gives you the power to easily perform a range of manipulations on PDFs including merging PDFs, deleting pages, and extracting and merging pages from separate PDF documents into one document. On top of that, you can encrypt and password-protect PDFs, add watermarks into documents, and much more. You can also use a subset of DDX, the XML language used by LiveCycle, to manipulate PDFs.


Here’s a one line example showing how you can merge two PDFs into one document.


<cfpdf action=”merge” source=”example1.pdf,example2.pdf”
destination=”result.pdf” />

Deleting a page is simple too:

<cfpdf action=”deletepages” pages=”1″ source=”example1.pdf”
destination=”result.pdf” />

ColdFusion Components

ColdFusion MX introduced a significant new feature, ColdFusion Components (CFCs).
Though ColdFusion isn’t an object-oriented language, CFCs give ColdFusion developers the power and flexibility to choose an object-oriented development approach. Ultimately,
CFCs are the single most important enhancement to the language in its history and have become the underpinnings for many new features.


The syntax for a basic CFC is quite simple. You define the component using the
<cfcomponent> tag and define functions using the <cffunction> tag. Arguments can be specified via the <cfargument> tag. Here’s a simple example:


<cfcomponent>
<cffunction name=”sayHello” access=”public” returntype=”string” >
<cfargument name=”toWhat” type=”string” />
<cfreturn “Hello #toWhat#!” />
</cffunction>
</cfcomponent>

This example defines a function called sayHello() which accepts an string argument and returns a string result.


There are several ways to invoke methods on components, but the most common way is to create an instance of the component using the createObject() function and then invoke methods in a manner similar to many other languages.




#HelloWorld.sayHello(“World”)#


The previous example would result in the string “Hello World” being output. All of the intricacies of component are outside the scope of this article. Suffice it to say that you have access to most features common to object oriented languages.


CFCs also have a myriad of other uses. For example, you can easily set the access attribute of any function to “remote.” This will allow your method to be executed via HTTP in several different ways. Most notably, all you need to do to create a web service is define some remote functions and browse directly to the CFC with “?wsdl” appended on the URL to generate a WSDL for your component. You can also specify a function name and arguments via the URL allowing for easy integration with basic HTTP-based remote procedure calls.


Additionally, CFCs are used when working with a ColdFusion feature known as Event Gateways. Recalling that ColdFusion is a “hub” that can talk to pretty much anything,
Event Gateways together with CFCs are the way that you can easily create applications which can interact with pretty much anything. Out of the box, ColdFusion comes with
Event Gatways that let you integrate with SMS, JMS, XMPP (Instant Messaging), and several other technologies.


Beyond that, CFCs are also used with ColdFusion 8’s built-in AJAX features. Most notably, the <cfajaxproxy> tag will generate client side JavaScript that acts as a proxy to your remote CFC. This enabled you to call methods on CFCs from client side code. It should come as no surprise that ColdFusion integrates very nicely with Flex, which is also an Adobe tool. As with AJAX, Flex applications tend to rely on a remote server. Again, CFCs are how this is accomplished in ColdFusion.


I’d also like to point out that ColdFusion is a dynamic language. Currently there is a lot of talk about the advantages that dynamic languages bring to the table compared to compiled languages.

Other Features

I could easily write for days on each individual feature of ColdFusion. However, I think my point has been made in the previous examples I’ve given so far. ColdFusion provides innumerable features in a simple, unassuming, but yet powerful package.

Did You Know that ColdFusion:


  • Integrates with Crystal Reports?
  • Ships with an Enterprise Server Monitor that can be used to monitor and analyze your application’s performance and memory usage as well as a plethora of other capabilities?
  • Has are several tags focused specifically on creating AJAX applications and RIAs?

If you’re not already a ColdFusion developer, or if you have not tried ColdFusion in a while, I sincerely encourage you to check it out. You can download a free development version from the Adobe’s ColdFusion area. Check it out, work with it, and see if it might be the database connectivity product you’re looking for!

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Popular Articles

Featured