Do you test under cfsetting?

This blog post probably only applies to people building reusable components and UDFs, but I ran into an interesting issue today I thought I’d share with my readers. MrBuzzy (he prefers to go by his nickname) reported an issue with pdfUtils when used on a site with cfsetting enablecfoutputonly=true turned on.

This tag is one of the ways in which you can help reduce the amount of whitespace ColdFusion generates. I talk about this in depth here: ColdFusion Whitespace Options.

My pdfUtils CFC has a method, getText, that extracts the text from a PDF document. This method uses DDX (XML) to create the instructions necessary to get the text:

<!--- Create DDX ---> <cfsavecontent variable="ddx"> <?xml version="1.0" encoding="UTF-8"?> <DDX xmlns="http://ns.adobe.com/DDX/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ns.adobe.com/DDX/1.0/ coldfusion_ddx.xsd"> <DocumentText result="Out1"> <PDF source="doc1"/> </DocumentText> </DDX> </cfsavecontent>

<cfset ddx = trim(ddx)> </code>

I had output=”false” on the CFC method, but that doesn’t prevent cfsavecontent from working. It just prevents any output from leaving the method. However, this immediately failed when used in context with cfsetting:

<cfsetting enablecfoutputonly="true"> <cfset pdf = createObject("component", "pdfutils")>

<cfset mypdf = expandPath(“./testpdf.pdf”)>

<cfset results = pdf.getText(mypdf)> <cfdump var=”#results#”> </code>

Of course, the fix was easy enough, I just wrapped the DDX in cfoutput:

<!--- Create DDX ---> <cfsavecontent variable="ddx"> <cfoutput> <?xml version="1.0" encoding="UTF-8"?> <DDX xmlns="http://ns.adobe.com/DDX/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ns.adobe.com/DDX/1.0/ coldfusion_ddx.xsd"> <DocumentText result="Out1"> <PDF source="doc1"/> </DocumentText> </DDX> </cfoutput> </cfsavecontent>

Simple enough of a fix, but I definitely will have to keep this in mind for my other CFCs.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. 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. You can even buy me a coffee!

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

Comments