Error with multiple PDF Generation in CF - coldfusion

I'm getting an error when producing a multi-page PDF.
The pages attribute is not specified for the MERGE action in the cfpdf tag.
The line that is causing the issue is: <cfpdf action="merge" source="#ArrayToList(variables.pdfList)#" destination="promega.pdf" overwrite="yes" />
I tried looking in Adobe's documentation bug cannot find an attribute pages for the merge action. Thoughts?
<!--- Append PDF to list for merge printing later --->
<cfset ArrayAppend(variables.pdfList, "#expandPath('.')#\general.pdf") />
<cfset variables.userAgenda = GetAttendeeSchedule(
variables.event_key,
variables.badgeNum
) />
<!--- Field CFID is the id of the agenda item; use this for certificate selection --->
<cfif variables.userAgenda.recordcount>
<cfloop query="variables.userAgenda">
<cfset variables.title = Trim(variables.userAgenda.CUSTOMFIELDNAMEONFORM) />
<cfpdfform source="#expandPath('.')#\promega_certificate.pdf" destination="#cfid#.pdf" action="populate">
<cfset variables.startdate = replace(CUSTOMFIELDSTARTDATE, "T", " ") />
<cfpdfformparam name="WORKSHOP" value="#variables.title#">
<cfpdfformparam name="NAME" value="#variables.badgeInfo.FirstName# #variables.badgeInfo.LastName#">
<cfpdfformparam name="STARTDATE" value="#DateFormat(variables.startdate, "medium" )#">
</cfpdfform>
<!--- Append PDF to list for merge printing later --->
<cfset ArrayAppend(variables.pdfList, "#expandPath('.')#\#cfid#.pdf") />
</cfloop>
</cfif>
<cfif ArrayLen(variables.pdfList)>
<cfpdf action="merge" source="#ArrayToList(variables.pdfList)#" destination="promega.pdf" overwrite="yes" />
<!--- Delete individual files --->
<cfloop list="#ArrayToList(variables.pdfList)#" index='i'>
<cffile action="delete" file="#i#" />
</cfloop>
<cftry>
<cffile action="delete" file="#expandPath('.')#\general.pdf" />
<cfcatch></cfcatch>
</cftry>
<cfheader name="Content-Disposition" value="attachment;filename=promega.pdf">
<cfcontent type="application/octet-stream" file="#expandPath('.')#\promega.pdf" deletefile="Yes">
<cflocation url="index.cfm" addtoken="false" />
</cfif>

This happens when source is a single file rather than a comma separated list of files. I'm guessing that if it's a single file is is expecting to extract some pages rather than add.

I tried the following on my coldfusion 9 machine and it worked just fine:
<cfset strPath = GetDirectoryFromPath(GetCurrentTemplatePath()) />
<Cfset pdflist = arrayNew(1)>
<Cfset pdflist[1] = "#strPath#page1.pdf">
<Cfset pdflist[2] = "#strPath#page2.pdf">
<cfpdf action="merge" source="#ArrayToList(pdflist)#" destination="#strPath#merged.pdf" overwrite="yes" />
You could try to merge the pages like this and check whether you still get an error:
<cfset strPath = GetDirectoryFromPath(GetCurrentTemplatePath()) />
<Cfset pdflist = arrayNew(1)>
<Cfset pdflist[1] = "#strPath#page1.pdf">
<Cfset pdflist[2] = "#strPath#page2.pdf">
<cfpdf action="merge" destination="#strPath#merged.pdf" overwrite="yes">
<Cfloop from=1 to="#arraylen(pdflist)#" index="x">
<cfpdfparam source="#pdfList[x]#">
</cfloop>
</cfpdf>

Related

Query created from Query returned from cfspreadsheet not having proper values

Today I came across a very odd case while reading a vlue from a spreadsheet and trying to filter them on a condition and a create a spreadsheet from the filtered data. Here are my steps
Read Excel sheet
<cfspreadsheet action="read" src="#local.sFilePath#" excludeHeaderRow="true" headerrow ="1" query="local.qExcelData" sheet="1" />
Create a holding Query
<cfset local.columnNames = "LoanNumber,Product," />
<cfset local.qSuccessData = queryNew(local.columnNames,"VarChar,VarChar") />
Filter the Excel returned query on a condition and add the valid ones into the new Holding query
<cfloop query="local.qExcelData" >
<cfif ListFind(local.nExceptionRowList,local.qExcelData.currentrow) EQ 0>
<cfset queryAddRow(local.qSuccessData) />
<cfset querySetCell(local.qSuccessData, 'LoanNumber', local.qExcelData['Loan Number']) />
<cfset querySetCell(local.qSuccessData, 'Product', local.qExcelData['Product']) />
</cfif>
</cfloop>
Create the new spreadsheet
<cfspreadsheet action="write" query="local.qSuccessData" filename="#local.sTempSuccessFile#" overwrite="true">
However I am getting the following content in my excel sheet
Loannumber Product
coldfusion.sql.column#87875656we coldfusion.sql.column#89989ER
Please help on this to get it work.
I believe the query loop is not mapping values to the Holding-Query properly.
Please modify your loop as below:
<cfloop query="local.qExcelData" >
<cfif ListFind(local.nExceptionRowList,local.qExcelData.currentrow) EQ 0>
<cfset queryAddRow(local.qSuccessData) />
<cfset querySetCell(local.qSuccessData, 'LoanNumber', local.qExcelData['Loan Number'][currentRow]) />
<cfset querySetCell(local.qSuccessData, 'Product', local.qExcelData['Product'][currentRow]) />
</cfif>
</cfloop>

How to compare two images in ColdFusion

I am trying to compare images and find if they are same or not. Images can have same name but the actual image might be different. The code that I have so far.
<cfset dirToReadFrom = #ExpandPath( '../properties-feed/unzipped/' )# />
<cfdirectory
action="list"
directory="#dirToReadFrom#"
listinfo="name"
name="qFile"
sort="asc"
filter="*.jpg"
/>
<cfset images = ArrayNew(1)>
<cfoutput query="qFile">
<cfset ArrayAppend(images, #qFile.name#)>
</cfoutput>
<cfset dirToCreate = #ExpandPath( './assets/images/resized/original/' )# />
<cfif not DirectoryExists(dirToCreate)>
<cfdirectory action = "create" directory = "#dirToCreate#" />
<cfoutput><p>Your directory has been created.</p></cfoutput>
</cfif>
<cfzip
action="unzip"
file="#ExpandPath( '../properties-feed/data.zip/' )#"
destination="#ExpandPath( './assets/images/resized/original/' )#"
overwrite="true"
/>
<cfset dirToReadFromOriginal = #ExpandPath( './assets/images/resized/original/' )# />
<cfdirectory
action="list"
directory="#dirToReadFromOriginal#"
listinfo="name"
name="qFileOriginal"
sort="asc"
filter="*.jpg"
/>
<cfset imagesLatest = ArrayNew(1)>
<cfoutput query="qFileOriginal">
<cfset ArrayAppend(imagesLatest, #qFileOriginal.name#)>
</cfoutput>
<!--- Loop over your current images --->
<cfloop query="qFileOriginal">
<!--- Check for a matching file name --->
<cfquery name="fileExists" dbtype="query">
SELECT
COUNT(*) AS num_Rec
FROM
qfile
WHERE
name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#qFileOriginal.name#" />
</cfquery>
<!--- do we have a matching file name? --->
<cfif val(fileExists.num_rec)>
<cfimage action="read" name="newImage" source="#dirToReadFrom##qFile.name#"/>
<cfimage action="read" name="originalImage" source="#dirToReadFromOriginal##qFileOriginal.name#"/>
<cfset newImageBlob = ImageGetBlob(newImage) />
<cfset originalImageBlob = ImageGetBlob(originalImage) />
<!--- Compare --->
<cfif toString(newImageBlob) eq toString(originalImageBlob) >
Images are same
<cfelse>
DIFFERENT
</cfif>
</cfif>
</cfloop>
The code doesn't seem to be working. Can Anyone see what am I doing wrong?
Update 1 from comments
The result that I actually get is that the first images are same and the rest of images in files are different. But this is not correct as most of the images that I am comparing are same.
Update 2 from comments
It incorrectly identifies same images as being different. What I actually get is that the first two images are same and the rest is different. Which is not right as most of the images I have are same.
I've always just done this with BinaryEncode(), and then compare the resulting strings. You have to be careful though, as compression can make the files different even though they look (to the eye) exactly the same.

Getting "method onRequest was not found" Error when binding CFC in cfselect in CF9. Works fine in CF8

I am getting error saying "Error invoking CFC componentname.cfc : The method onRequest was not found in component ..\filepath\Application.cfc".
This works fine with CF8 but not CF9 with same code. Both environments use Apache and Fusebox 5. The method onRequest exists in application.cfc.
Please help.
CODE FOR CFC BIND:
<cfselect name="officeNum" id="officeNum" bind="cfc: userYODSU.GetOfficeList({empID},{fy})" display="officeNameTxt" value="officeNum" bindOnLoad="true"><option value="">---</option></cfselect>
Code in APPLICATION.CFC
<cfcomponent output="false">
<cfprocessingdirective suppresswhitespace="true">
<!---
Copyright 2006-2007 TeraTech, Inc. http://teratech.com/
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--->
<!--- code that must execute at the very start of every single request --->
<!--- FB5: allow "" default - FB41 required this variable: --->
<cfparam name="variables.FUSEBOX_APPLICATION_PATH" default="" />
<!--- FB5: application key - FB41 always uses 'fusebox': --->
<cfparam name="variables.FUSEBOX_APPLICATION_KEY" default="fusebox" />
<!--- FB51: allow application to be included from other directories: --->
<cfparam name="variables.FUSEBOX_CALLER_PATH" default="#replace(getDirectoryFromPath(getBaseTemplatePath()),"\","/","all")#" />
<!--- FB55: easy way to override fusebox.xml parameters programmatically: --->
<cfparam name="variables.FUSEBOX_PARAMETERS" default="#structNew()#" />
<cfparam name="variables.attributes" default="#structNew()#" />
<cfset structAppend(attributes,URL,true) />
<cfset structAppend(attributes,form,true) />
<!--- FB5: uses request.__fusebox for internal tracking of compiler / runtime operations: --->
<cfset request.__fusebox = structNew() />
<!--- FB55: bleeding variables scope back and forth between fusebox5.cfm and this CFC for backward compatibility --->
<cfset variables.exposed = structNew() />
<!--- FB55: scaffolder integration --->
<cfif structKeyExists(attributes,"scaffolding.go")>
<!--- if we're not already executing the scaffolder, branch to it --->
<cfif findNoCase("/scaffolder/",CGI.SCRIPT_NAME) eq 0>
<cftry>
<cfinclude template="/scaffolder/manager.cfm" />
<cfcatch type="missinginclude">
<cfif structKeyExists(attributes,"scaffolding.debug")>
<cfrethrow />
</cfif>
<cfthrow type="fusebox.noScaffolder" message="Scaffolder not found" detail="You requested the scaffolder but /scaffolder/index.cfm does not exist." />
</cfcatch>
</cftry>
</cfif>
</cfif>
<cffunction name="bleed" returntype="any" access="public" output="false">
<cfargument name="outerVariables" type="any" required="true" />
<cfset variables.exposed = arguments.outerVariables />
<!--- expose known variables: --->
<cfset variables.exposed.attributes = variables.attributes />
<cfreturn this />
</cffunction>
<cffunction name="onApplicationStart" output="false">
<!--- FB5: myFusebox is an object but has FB41-compatible public properties --->
<cfset variables.myFusebox = createObject("component","myFusebox").init(variables.FUSEBOX_APPLICATION_KEY,variables.attributes,variables) />
<!--- expose known variables: --->
<cfset variables.exposed.myFusebox = variables.myFusebox />
<!--- FB55: guarantee XFA struct exists --->
<cfparam name="variables.xfa" default="#structNew()#" />
<!--- FB51: ticket 164: add OO synonym for attributes scope --->
<cfparam name="variables.event" default="#createObject('component','fuseboxEvent').init(attributes,xfa,myFusebox)#" />
<!--- expose known variables: --->
<cfset variables.exposed.xfa = variables.xfa />
<cfset variables.exposed.event = variables.event />
<cfset loadFusebox() />
</cffunction>
<cffunction name="onSessionStart" output="false">
</cffunction>
<cffunction name="onRequestStart" output="false">
<cfargument name="targetPage" type="string" required="true" />
<cfset var doCompile = true />
<!--- ensure CFC / Web Service / Flex Remoting calls are not intercepted --->
<cfif right(arguments.targetPage,4) is ".cfc">
<cfset doCompile = false />
<cfset structDelete(variables,"onRequest") />
<cfset structDelete(this,"onRequest") />
</cfif>
<!--- onApplicationStart() may create this (on first request) --->
<cfif not structKeyExists(variables,"myFusebox")>
<!--- FB5: myFusebox is an object but has FB41-compatible public properties --->
<cfset variables.myFusebox = createObject("component","myFusebox").init(variables.FUSEBOX_APPLICATION_KEY,variables.attributes,variables) />
<!--- expose known variables: --->
<cfset variables.exposed.myFusebox = variables.myFusebox />
</cfif>
<!--- FB55: guarantee XFA struct exists --->
<cfparam name="variables.xfa" default="#structNew()#" />
<!--- FB51: ticket 164: add OO synonym for attributes scope --->
<cfparam name="variables.event" default="#createObject('component','fuseboxEvent').init(variables.attributes,variables.xfa,variables.myFusebox)#" />
<!--- expose known variables: --->
<cfset variables.exposed.xfa = variables.xfa />
<cfset variables.exposed.event = variables.event />
<cfif variables.myFusebox.parameters.load>
<cflock name="#application.ApplicationName#_fusebox_#variables.FUSEBOX_APPLICATION_KEY#" type="exclusive" timeout="300">
<cfif variables.myFusebox.parameters.load>
<cfset loadFusebox() />
<cfelse>
<!--- _fba should *not* be exposed --->
<cfset _fba = application[variables.FUSEBOX_APPLICATION_KEY] />
<!--- fix attributes precedence --->
<cfif _fba.precedenceFormOrURL is "URL">
<cfset structAppend(variables.attributes,URL,true) />
</cfif>
<!--- set the default fuseaction if necessary --->
<cfif not structKeyExists(variables.attributes,_fba.fuseactionVariable) or trim(variables.attributes[_fba.fuseactionVariable]) is "">
<cfset variables.attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction />
</cfif>
<cfset variables.attributes[_fba.fuseactionVariable] = trim(variables.attributes[_fba.fuseactionVariable]) />
<cfset variables.attributes.fuseaction = variables.attributes[_fba.fuseactionVariable] />
</cfif>
</cflock>
<cfelse>
<cfset _fba = application[variables.FUSEBOX_APPLICATION_KEY] />
<!--- fix attributes precedence --->
<cfif _fba.precedenceFormOrURL is "URL">
<cfset structAppend(variables.attributes,URL,true) />
</cfif>
<!--- set the default fuseaction if necessary --->
<cfif not structKeyExists(variables.attributes,_fba.fuseactionVariable) or trim(variables.attributes[_fba.fuseactionVariable]) is "">
<cfset variables.attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction />
</cfif>
<cfset variables.attributes[_fba.fuseactionVariable] = trim(variables.attributes[_fba.fuseactionVariable]) />
<cfset variables.attributes.fuseaction = variables.attributes[_fba.fuseactionVariable] />
</cfif>
<!---
Fusebox 4.1 did not set attributes.fuseaction or default the fuseaction variable until
*after* fusebox.init.cfm had run. This made it hard for fusebox.init.cfm to do URL
rewriting. For Fusebox 5, we default the fuseaction variable and set attributes.fuseaction
before fusebox.init.cfm so it can rely on attributes.fuseaction and rewrite that. However,
in order to maintain backward compatibility, we need to allow fusebox.init.cfm to set
attributes[_fba.fuseactionVariable] and still have that reflected in attributes.fuseaction
and for that to actually be the request that gets processed.
--->
<cfif _fba.debug>
<cfset variables.myFusebox.trace("Fusebox","Including fusebox.init.cfm") />
</cfif>
<cftry>
<!--- _fba_ttr_fav and _ba_attr_fa should *not* be exposed --->
<cfset _fba_attr_fav = variables.attributes[_fba.fuseactionVariable] />
<cfset _fba_attr_fa = variables.attributes.fuseaction />
<cfinclude template="#_fba.getCoreToAppRootPath()#fusebox.init.cfm" />
<cfif variables.attributes.fuseaction is not _fba_attr_fa>
<cfif variables.attributes.fuseaction is not variables.attributes[_fba.fuseactionVariable]>
<cfif variables.attributes[_fba.fuseactionVariable] is not _fba_attr_fav>
<!--- inconsistent modification of both variables?!? --->
<cfthrow type="fusebox.inconsistentFuseaction"
message="Inconsistent fuseaction variables"
detail="Both attributes.fuseaction and attributes[{fusebox}.fuseactionVariable] changed in fusebox.init.cfm so Fusebox doesn't know what to do with the values!" />
<cfelse>
<!--- ok, only attributes.fuseaction changed --->
<cfset variables.attributes[_fba.fuseactionVariable] = variables.attributes.fuseaction />
</cfif>
<cfelse>
<!--- ok, they were both changed and they match --->
</cfif>
<cfelse>
<!--- attributes.fuseaction did not change --->
<cfif variables.attributes[_fba.fuseactionVariable] is not _fba_attr_fav>
<!--- make attributes.fuseaction match the other changed variable --->
<cfset variables.attributes.fuseaction = variables.attributes[_fba.fuseactionVariable] />
<cfelse>
<!--- ok, neither variable changed --->
</cfif>
</cfif>
<cfcatch type="missinginclude" />
</cftry>
<cfif doCompile>
<!---
must special case development-circuit-load mode since it causes circuits to reload during
the compile (post-load) phase and therefore must be exclusive
--->
<cfif _fba.debug>
<cfset variables.myFusebox.trace("Fusebox","Compiling requested fuseaction '#variables.attributes.fuseaction#'") />
</cfif>
<!--- _parsedFileData should *not* be exposed --->
<cfif _fba.mode is "development-circuit-load">
<cflock name="#application.ApplicationName#_fusebox_#variables.FUSEBOX_APPLICATION_KEY#" type="exclusive" timeout="300">
<cfset _parsedFileData = _fba.compileRequest(attributes.fuseaction,myFusebox) />
</cflock>
<cfelse>
<cflock name="#application.ApplicationName#_fusebox_#variables.FUSEBOX_APPLICATION_KEY#" type="readonly" timeout="300">
<cfset _parsedFileData = _fba.compileRequest(attributes.fuseaction,myFusebox) />
</cflock>
</cfif>
</cfif>
</cffunction>
<!--- excuse the formatting here - it is done to completely suppress whitespace --->
<cffunction name="onRequest"><cfargument
name="targetPage" type="string" required="true" /><cfsetting
enablecfoutputonly="true">
<cfif variables.myFusebox.parameters.execute>
<cfif _fba.debug>
<cfset myFusebox.trace("Fusebox","Including parsed file for '#variables.attributes.fuseaction#'") />
</cfif>
<cftry>
<!---
readonly lock protects against including the parsed file while
another threading is writing it...
--->
<cflock name="#_parsedFileData.lockName#" type="readonly" timeout="30">
<cfinclude template="#_parsedFileData.parsedFile#" />
</cflock>
<cfcatch type="missinginclude">
<cfif right(cfcatch.missingFileName, len(_parsedFileData.parsedName)) is _parsedFileData.parsedName>
<cfthrow type="fusebox.missingParsedFile"
message="Parsed File or Directory not found."
detail="Attempting to execute the parsed file '#_parsedFileData.parsedName#' threw an error. This can occur if the parsed file does not exist in the parsed directory or if the parsed directory itself is missing." />
<cfelse>
<cfrethrow />
</cfif>
</cfcatch>
</cftry>
</cfif>
<cfsetting enablecfoutputonly="false">
</cffunction>
<cffunction name="onRequestEnd" output="true">
<cfargument name="targetPage" type="string" required="true" />
<cfif structKeyExists(variables,"myFusebox")>
<cfset variables.myFusebox.trace("Fusebox","Request completed") />
</cfif>
<cfif isDefined("_fba.debug") and _fba.debug and structKeyExists(variables,"myFusebox") and right(arguments.targetPage,4) is not ".cfc">
<cfoutput>#variables.myFusebox.renderTrace()#</cfoutput>
</cfif>
</cffunction>
<cffunction name="onSessionEnd" output="false">
</cffunction>
<cffunction name="onApplicationEnd" output="false">
</cffunction>
<cffunction name="onError">
<cfargument name="exception" />
<cfset var stack = 0 />
<cfset var prefix = "Raised at " />
<!--- top-level exception is always event name / expression for Application.cfc (but not fusebox5.cfm) --->
<cfset var caughtException = arguments.exception />
<cfif structKeyExists(caughtException,"rootcause")>
<cfset caughtException = caughtException.rootcause />
</cfif>
<cfif listFirst(caughtException.type,".") is "fusebox">
<cfif isDefined("_fba.debug") and _fba.debug and structKeyExists(variables,"myFusebox")>
<cfset variables.myFusebox.trace("Fusebox","Caught Fusebox exception '#caughtException.type#'") />
<cfif structKeyExists(caughtException,"tagcontext")>
<cfloop index="stack" from="1" to="#arrayLen(caughtException.tagContext)#">
<cfset variables.myFusebox.trace("Fusebox",prefix &
caughtException.tagContext[stack].template & ":" &
caughtException.tagContext[stack].line) />
<cfset prefix = "Called from " />
</cfloop>
</cfif>
</cfif>
<cfif not isDefined("_fba.errortemplatesPath") or (
structKeyExists(variables,"attributes") and structKeyExists(variables,"myFusebox") and
not _fba.handleFuseboxException(caughtException,variables.attributes,variables.myFusebox,variables.FUSEBOX_APPLICATION_KEY)
)>
<cfif isDefined("_fba.debug") and _fba.debug and structKeyExists(variables,"myFusebox")>
<cfoutput>#variables.myFusebox.renderTrace()#</cfoutput>
</cfif>
<cfthrow object="#caughtException#" />
</cfif>
<cfelse>
<cfif isDefined("_fba.debug") and _fba.debug and structKeyExists(variables,"myFusebox")>
<cfset variables.myFusebox.trace("Fusebox","Request failed with exception '#caughtException.type#' (#caughtException.message#)") />
<cfif structKeyExists(caughtException,"tagcontext")>
<cfloop index="stack" from="1" to="#arrayLen(caughtException.tagContext)#">
<cfset variables.myFusebox.trace("Fusebox",prefix &
caughtException.tagContext[stack].template & ":" &
caughtException.tagContext[stack].line) />
<cfset prefix = "Called from " />
</cfloop>
</cfif>
<cfoutput>#variables.myFusebox.renderTrace()#</cfoutput>
</cfif>
<cfthrow object="#caughtException#" />
</cfif>
<!--- if we hit an error before starting the request, prevent the request from running --->
<cfset myFusebox.parameters.execute = false />
</cffunction>
<cffunction name="override" returntype="void" access="public" output="false">
<cfargument name="name" type="string" required="true" />
<cfargument name="value" type="any" required="true" />
<cfargument name="useThisScope" type="boolean" default="false" />
<cfif arguments.useThisScope>
<cfset this[arguments.name] = arguments.value />
<cfelse>
<cfset variables[arguments.name] = arguments.value />
</cfif>
</cffunction>
<cffunction name="onFuseboxApplicationStart">
</cffunction>
<cffunction name="loadFusebox" access="private" output="false">
<!--- ticket 232: extend request timeout value on framework load --->
<cfsetting requesttimeout="600" />
<cfif not structKeyExists(application,variables.FUSEBOX_APPLICATION_KEY) or variables.myFusebox.parameters.userProvidedLoadParameter>
<!--- can't be conditional: we don't know the state of the debug flag yet --->
<cfset variables.myFusebox.trace("Fusebox","Creating Fusebox application object") />
<cfset _fba = createObject("component","fuseboxApplication") />
<cfset application[variables.FUSEBOX_APPLICATION_KEY] = _fba.init(variables.FUSEBOX_APPLICATION_KEY,variables.FUSEBOX_APPLICATION_PATH,variables.myFusebox,variables.FUSEBOX_CALLER_PATH,variables.FUSEBOX_PARAMETERS) />
<cfelse>
<!--- can't be conditional: we don't know the state of the debug flag yet --->
<cfset variables.myFusebox.trace("Fusebox","Reloading Fusebox application object") />
<cfset _fba = application[variables.FUSEBOX_APPLICATION_KEY] />
<!--- it exists and the load is implicit, not explicit (via user) so just reload XML --->
<cfset _fba.reload(variables.FUSEBOX_APPLICATION_KEY,variables.FUSEBOX_APPLICATION_PATH,variables.myFusebox,variables.FUSEBOX_PARAMETERS) />
</cfif>
<!--- fix attributes precedence --->
<cfif _fba.precedenceFormOrURL is "URL">
<cfset structAppend(variables.attributes,URL,true) />
</cfif>
<!--- set the default fuseaction if necessary --->
<cfif not structKeyExists(variables.attributes,_fba.fuseactionVariable) or variables.attributes[_fba.fuseactionVariable] is "">
<cfset variables.attributes[_fba.fuseactionVariable] = _fba.defaultFuseaction />
</cfif>
<!--- set this up for fusebox.appinit.cfm --->
<cfset variables.attributes.fuseaction = variables.attributes[_fba.fuseactionVariable] />
<!--- flag this as the first request for the application --->
<cfset variables.myFusebox.applicationStart = true />
<!--- force parse after reload for consistency in development modes --->
<cfif _fba.mode is not "production" or variables.myFusebox.parameters.userProvidedLoadParameter>
<cfset variables.myFusebox.parameters.parse = true />
</cfif>
<!--- need all of the above set before we attempt any compiles! --->
<cfif variables.myFusebox.parameters.parseall>
<cfset _fba.compileAll(variables.myFusebox) />
</cfif>
<!--- FB55: template method to allow no-XML application initialization --->
<cfif _fba.debug>
<cfset variables.myFusebox.trace("Fusebox","Executing onFuseboxApplicationStart()") />
</cfif>
<cfset onFuseboxApplicationStart() />
<!--- FB5: new appinit include file --->
<cfif _fba.debug>
<cfset variables.myFusebox.trace("Fusebox","Including fusebox.appinit.cfm") />
</cfif>
<cftry>
<cfinclude template="#_fba.getCoreToAppRootPath()#fusebox.appinit.cfm" />
<cfcatch type="missinginclude" />
</cftry>
<!--- ticket 269 ensure there is no double reload at CF startup --->
<cfset variables.myFusebox.parameters.load = false />
</cffunction>
</cfprocessingdirective>
</cfcomponent>
I dunno why you'd be getting the error you're seeing, but in CF9 you don't need to do all that horsing around deleting onRequest(), you can simply have an onCfcRequest() method in there, which'll get called instead of onRequest() when requests for CFCs are made. So doing that could remove the situation in which the error situation arises.
Finally I was able to resolve this issue. I figured that the error shows only in the localhost but not on any servers. Also, found that the problem was only with the cfselect with bind cfc. I didn't see any difference with the settings in localhost and other servers. So I tried some changes to the fusebox code and fixed it. Following change in fusebox5.cfm made it working.
<cftry>
<cfset __fuseboxAppCfc.onRequest(CGI.SCRIPT_NAME) />
<cfset __fuseboxAppCfc.onRequestEnd(CGI.SCRIPT_NAME) />
<cfcatch type="any">
<cfset __fuseboxAppCfc.onError(cfcatch)>
</cfcatch>
</cftry>
Changed this to:
<cftry>
<cfif right(CGI.SCRIPT_NAME,"4") NEQ ".cfc">
<cfset __fuseboxAppCfc.onRequest(CGI.SCRIPT_NAME) />
</cfif>
<cfset __fuseboxAppCfc.onRequestEnd(CGI.SCRIPT_NAME) />
<cfcatch type="any">
<cfset __fuseboxAppCfc.onError(cfcatch)>
</cfcatch>
</cftry>

Variable Datasource is undefined

I have defined a datasource in the admin console of ColdFusion Admin. I have declared the configuration with the same datasource name in set_datasource_util file. I have a webpage that connects to a DB(Oracle) using the datasource given and it works fine most of the time. But lately I am starting to see exceptions like "Variable datasource-name(my app name) is undefined". I am not able to identify the root cause as I am not able to recreate it as it works most of the time. I can say on average on 1000 hits of page, it fails 1 time with that exception. Can anyone help in identifying what could be the possible issue so that I can investigate in that direction.
I have configured WOCD080P_ABC in CFAdmin.
Below is the code from Application.cfm
<cfif client.securityLevel NEQ ''>
<cfinvoke component="#siteroot#.CFC.Set_Data_Source_Util" method="fnSetABCDataSource" returnvariable="ABCDataSourceDefinition">
<cfinvokeargument name="Environment" value="#variables.thisServerType#" />
</cfinvoke>
<cfif ABCDataSourceDefinition.DataSource NEQ 'Error'>
<cfset DATASOURCE_ABC = ABCDataSourceDefinition.DataSource />
<cfset DBUSER_ABC = ABCDataSourceDefinition.DBUser />
<cfset DBPASSWORD_ABC = ABCDataSourceDefinition.DBPassword />
</cfif>
</cfif>
Below is the code from Set_datasource_UTil :
<cffunction name="fnSetABCDataSource" access="public" returntype="struct">
<cfargument name="Environment" type="string" required="yes">
<cfset ReturnParameters = StructNew() />
<cfif Environment IS 'prod'>
<cfset ReturnParameters.DataSource = 'WOCD080P_ABC' />
<cfset ReturnParameters.DBUser = ''/>
<cfset ReturnParameters.DBPassword = '' />
<cfelse>
<cfset ReturnParameters.DataSource = 'WOCD080T_ABC'/>
<cfset ReturnParameters.DBUser = ''/>
<cfset ReturnParameters.DBPassword = '' />
</cfif>
<cfreturn ReturnParameters>
</cffunction>
Below is the code which i am executing from HTML file.
<cfinvoke component="#siteroot#.cfc.ABC_UTIL" method="GetRegion" returnVariable = "USregion" >
<cfinvokeargument name="dbSource" value=#DATASOURCE_ABC# />
<cfinvokeargument name="dbUser" value=#DBUSER_ABC# />
<cfinvokeargument name="dbPass" value=#DBPASSWORD_ABC# />
</cfinvoke>
The code in the HTML file works most of the time but breaks sometime with error Variable DATASOURCE_ABC not defined.
Any help appreciated.
Please ensure you are using the var keyword for local variables inside of CFC Functions:
<cfset var ReturnParameters = StructNew() />
CF9+ local scope can be used in lieu of var:
<cfset local.ReturnParameters = StructNew() />
For extra protection, improve this statement in your application.cfm:
<cfif isDefined("ABCDataSourceDefinition.DataSource")
AND ABCDataSourceDefinition.DataSource NEQ 'Error'>
<cfset DATASOURCE_ABC = ABCDataSourceDefinition.DataSource />
<cfset DBUSER_ABC = ABCDataSourceDefinition.DBUser />
<cfset DBPASSWORD_ABC = ABCDataSourceDefinition.DBPassword />
</cfif>
Also, the could be another source of why a datasource is not being defined. I assume you have an interceptor that catches that before this datasource error occurs and sends them to a login page or something.

CF: Saving a Fusioncharts graph as an image to email it

Does anyone have an example of this? Google is not my friend tonight. I have the newest version of FusionCharts. I'm trying to figure out how to save a graph as an image file to email it.
I know how to save and then insert images into HTML emails, and I've done this before with other graph products. I just cannot fine 1 good example of how to do this with Fusioncharts.
Thanks!
Use the following code in a template and point the imageSaveURL property at that template.
Your chart submits all necessary data for the chart to be reconstructed. In my example I'm serving it to the browser but you could save it locally and then attach to a cfmail if necessary.
I'm pretty sure I got this from the fusioncharts forums originally. This was updated for fusioncharts 3.1.
<cfif structKeyExists(Form, "width") >
<cfset width = int(Form.width) />
<cfelse>
<cfset width = int(Form.Meta_Width) />
</cfif>
<cfif structKeyExists(Form, "height") >
<cfset height = int(Form.height) />
<cfelse>
<cfset height = int(Form.Meta_Height) />
</cfif>
<cfif structKeyExists(Form, "data") >
<cfset Form.data = Form.data />
<cfelse>
<cfif structKeyExists(Form, "stream") >
<cfset Form.data = Form.stream />
</cfif>
</cfif>
<cfset user = viewState.getValue("user", structNew()) />
<!--- Impose some limits to mitigate DOS attacks --->
<cfif Not (0 lte width and width lte 5000)>
<cfthrow message="Width out of range." />
</cfif>
<cfif Not (0 lte height and height lte 5000)>
<cfthrow message="Height out of range." />
</cfif>
<!--- Check if we have the chart data --->
<cfif Not StructKeyExists(Form, "data") or Not Len(Trim( Form.data ))>
<cfthrow message="Image Data not supplied." />
</cfif>
<!--- Default background color is white --->
<cfif Not StructKeyExists(Form, "bgcolor") or Not Len(Trim( Form.bgcolor ))>
<cfset Form.bgcolor = "FFFFFF" />
</cfif>
<cfset gColor = CreateObject("java", "java.awt.Color") />
<cfset chart = CreateObject("java", "java.awt.image.BufferedImage") />
<cfset chart.init( JavaCast("int", width), JavaCast("int", height), chart.TYPE_3BYTE_BGR) />
<cfset gr = chart.createGraphics() />
<cfset gr.setColor( gColor.decode("##" & Form.bgcolor) ) />
<cfset gr.fillRect(0, 0, JavaCast("int", width), JavaCast("int", height)) />
<!--- Get rows with pixels --->
<cfset rows = ListToArray(Form.data, ";") />
<cfloop from="1" to="#ArrayLen(rows)#" index="i">
<cfset pixels = ListToArray(rows[i], ",") />
<!--- Horizontal index (x scale) --->
<cfset horizIndex = 0 />
<cfloop from="1" to="#ArrayLen(pixels)#" index="j">
<cfif ListLen(pixels[j], "_") eq 2>
<!--- We have the color and the number of times it must be repeated --->
<cfset color = ListGetAt(pixels[j], 1, "_") />
<cfset repeat = ListGetAt(pixels[j], 2, "_") />
<cfelse>
<!--- Background color; how many pixels to skip --->
<cfset color = "" />
<cfset repeat = ListGetAt(pixels[j], 1, "_") />
</cfif>
<cfif Len(Trim(color))>
<!--- If the hexadecimal code is less than 6 characters, prefix with 0 to get a 6 char color --->
<cfif Len(Trim(color)) lt 6>
<cfset color = RepeatString(0, 6 - Len(Trim(color))) & color />
</cfif>
<!--- Draw a horizontal line for the number of pixels we must repeat --->
<cfset gr.setColor(gColor.decode("##" & color)) />
<cfset gr.drawLine(JavaCast("int", horizIndex), JavaCast("int", i - 1), JavaCast("int", horizIndex + repeat -1), JavaCast("int", i - 1)) />
</cfif>
<cfset horizIndex = horizIndex + repeat />
</cfloop>
</cfloop>
<!--- Get writer for Jpeg --->
<cfset writer = "" />
<cfset iter = CreateObject("java", "javax.imageio.ImageIO").getImageWritersByFormatName("jpg") />
<cfloop condition="iter.hasNext()">
<cfset writer = iter.next() />
</cfloop>
<!--- Set Jpeg quality to maximum --->
<cfset jpgParams = CreateObject("java", "javax.imageio.plugins.jpeg.JPEGImageWriteParam").init( CreateObject("java", "java.util.Locale").init("en") ) />
<cfset jpgParams.setCompressionMode( jpgParams.MODE_EXPLICIT ) />
<cfset jpgParams.setCompressionQuality( 1 ) />
<!--- Write image to a memory stream --->
<cfset imageOutput = CreateObject("java", "java.io.ByteArrayOutputStream").init() />
<cfset writer.setOutput( CreateObject("java", "javax.imageio.stream.MemoryCacheImageOutputStream").init( imageOutput ) ) />
<cfset writer.write(JavaCast("null", 0), CreateObject("java", "javax.imageio.IIOImage").init(chart, JavaCast("null", 0), JavaCast("null", 0)), jpgParams) />
<!--- Stream the image to the browser (hint browser to display the Save dialog) --->
<cfset filename="whatever.jpg" />
<cfheader name="Content-Disposition" value="attachment; filename=""#filename#""">
<cfcontent type="image/jpeg" variable="#imageOutput.toByteArray()#">
Checkout out the latest blog post Export Chart Images at Server Side where two options (wkhtmltoimage and PhantomJS. ) has been described with step-by-step instructions for both.
For ColdFusion, you can try the below code:
For example:
<cfexecute name="C:\Program Files\wkhtmltopdf\wkhtmltoimage.exe" arguments="--javascript-delay 10000 http://docs.fusioncharts.com/charts/Code/MyFirstChart/ms-weekly-sales-no-animation.html savedimage.png" />
While executing the above script, we provide the following arguments:
Call wkhtmltoimage
Pass the URL of your webpage to it
Pass the path and name of the image file (with extension) where the image will be saved
If required, any additional delay to ensure the chart is completely rendered.