Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

Easy-to-Use Solution for Developers

Easy-to-Use Solution for Developers

As ColdFusion engineers, we like to think that our job is to make ColdFusion developers’ lives easier. This was the exact mind set we applied while working on this task. We thought, what can we create so that all that developers need to do is wrap their HTML with a ColdFusion tag, so that conversion occurs once the browser invokes the web request? Thus, the cfdocument tag syntax was born. Here’s an overview of the syntax:

<cfdocument format="flashpaper/PDF">
<!—insert your HTML, CFML, and cfdocumentitem tags->

This is it! No messy XML, Java classpath configuration, or registering native libraries. Best of all, it is a part of the ColdFusion engine. Once you install ColdFusion, this feature is available to you. You don’t need to change anything in your existing HTML/CFML content.

In addition to the simplicity of the tag’s functionality, we also added attributes to help you manipulate document layouts (see Table 1). The only tag requirement is the format attribute, which specifies to the ColdFusion engine which type of file to generate (PDF or FlashPaper); the others are optional attributes.

Table 1. cfdocument Attributes
Attributes Required Optional Functionality
Format yes no Dictates what format to generate (PDF or FlashPaper)
MarginTop no yes Defaults to 0.5 inches (“Unit” attribute changes unit)
MarginBottom no yes Defaults to 0.5 inches (“Unit” attribute changes unit)
MarginLeft no yes Defaults to 0.5 inches (“Unit” attribute changes unit)
MarginRight no yes Defaults to 0.5 inches (“Unit” attribute changes unit)
BackgroundVisible no yes Allows background color or images to appear (disabling this attribute speeds document processing and limits memory usage)
Orientation no yes Specifies landscape or portrait
PageType no yes Specifies letter, legal, A4, A5, B4, B5, B4-JIS, B5-JIS, and custom
PageWidth no yes Specifies page width when selecting “Custom” PageType
PageHeight no yes Specifies page height when selecting “Custom” PageType
Encryption no yes Sets 128-bit, 40-bit, or none (PDF-only feature)
OwnerPassword no yes Sets owner password of the document when encryption is on
UserPassword no yes Sets user password of the document when encryption is on
Permissions no yes Establishes permission types
Unit no yes Sets inches or centimeters
FontEmbed no yes Embeds font with the document
Filename no yes Chooses where to save the file
Overwrite no yes Overwrites file if it exists
Name no yes Saves result content to a CF variable
Scale no yes Specifies zoom factor of the document

Besides providing basic printing functionality, the cfdocument tag also had to be robust and conform to standards. Our first priority was to support HTML 4.01. This standard was required before anything else because most of our users use the HTML 4.01 standard. Second, CSS versions 1 and 2 were required because style sheets are an important part of HTML formatting, making it a feature requirement.

The remaining tasks were to provide image, HTML links, security, and accessibility support so that generated rich documents act similarly to browser-rendered content. Furthermore, to support fonts that a user specifies within HTML content, the team built the cfdocument tag to work with the ColdFusion font manager to locate necessary fonts on the system. We took some of the PDF-specific functionality and made bidirectional language (such as Arabic, Hebrew) support possible for PDF-formatted documents.