Adding print support to ColdFusion Builder Extensions

While jogging this morning (I won’t call what I do running, at best, it’s fast shambling that would probably just barely keep me ahead of the zombie horde) it occurred to me that it would probably be trivial to add basic print support to ColdFusion Builder extensions. I’m not talking about the cfprint tag, but printing on your client machine. I whipped up the following quick demo. Since extensions use a “mini browser”, shouldn’t it be possible to just use JavaScript to print?

First, I created a very basic ide_config.xml. For those who have not written any CFB extensions, the ide_config.xml file dictates how your extension interacts with the IDE. I wanted to test both “XML mode” and “HTML mode” responses to see if printing would work in one and not the other. Here is my XML:

<application> <name>TestExtention</name> <author>Raymond Camden</author> <version>0</version> <email>ray@camdenfamily.com</email> <menucontributions > <contribution target="editor"> <menu name="Run Test Extension"> <action name="Run XML Test" handlerid="xmltest" showResponse="true" /> <action name="Run HTML Test" handlerid="htmltest" showResponse="true" /> </menu> </contribution> </menucontributions> <handlers> <handler id="xmltest" type="CFM" filename="test_xml.cfm" /> <handler id="htmltest" type="CFM" filename="test_html.cfm" /> </handlers> </application>

As you can see, I've got two tests - "Run XML Test" and "Run HTML Test". I started off with the HTML response:

<style> @media print { .hideforprint { display:none; } } </style> <cfoutput> <div class="hideforprint">First test - print: <a href="javascript:window.print()">print!</a><br/></div> Testing! </cfoutput>

I've got a very basic JavaScript window.print command along with some simple CSS to hide it when printing. I've got one line of HTML ("Testing!") and - well, that's it. Guess what? It worked perfectly. I'm using an Adobe PDF print driver for testing. Here is a screen shot of the result:

I then tried the exact same, but in XML mode:

<cfheader name="Content-Type" value="text/xml"> <cfoutput> <response showresponse="true"> <ide> <dialog width="500" height="500" title="This is Handler Two" /> <body> <![CDATA[ <style> @media print { .hideforprint { display:none; } } </style> <div class="hideforprint">First test - print: <a href="javascript:window.print()">print!</a><br/></div> Testing: Testing! <p/> ]]> </body> </ide> </response></cfoutput>

This too worked perfectly. For the heck of it, I quickly modified the varScoper CFB extension to add a print link to the bottom of the report:

And not surprisingly, it worked fine as well. I've included the PDF result as an attachment to the blog entry.

Download attached file.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate looking for his next gig. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments