ColdFusion for the Web Developer, Part 2
https://www.htmlgoodies.com/primers/database/article.php/3757636/ColdFusion-for-the-Web-Developer-Part-2.htm (Back to article)
PDF ManipulationSeeing 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 ComponentsColdFusion 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.
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.
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.