CFLib.org – Common Function Library Project

cfcToPrinter(cfcType [, outputType])

Last updated August 30, 2005
Download UDF

author

Jared Rypka-Hauer                                 Jared Rypka-Hauer

Version: 1 | Requires: ColdFusion MX7 | Library: UtilityLib

Description:
This UDF takes a fully-qualified CFC name (i.e. "CFIDE.componentutils.cfcexplorer") as the only required parameter and displays the results of cfcexplorer.cfc's getCfcAsHtml() function as HTML, FlashPaper, or PDF.

Return Values:
Returns either a string or binary data.

Example:

<cfcontent type="application/x-shockwave-flash" reset="yes" variable="#cfcToPrinter('CFIDE.componentutils.cfcexplorer')#" />

Parameters:

Name Description Required
cfcType The CFC type. Yes
outputType Can be html, flashpaper, or pdf. Defaults to flashpaper. No

Full UDF Source:

<!---
Given the fully-qualified path of a CFC, it renders the cfcexplorer.getcfcashtml() output to html, flahspaper, or PDF for printing as reference.

@param cfcType      The CFC type. (Required)
@param outputType      Can be html, flashpaper, or pdf. Defaults to flashpaper. (Optional)
@return Returns either a string or binary data.
@author Jared Rypka-Hauer (jared@web-relevant.com)
@version 1, August 30, 2005
--->

<cffunction name="cfcToPrinter" access="public" output="false" returntype="any">
<cfargument name="cfcType" type="string" required="true" />
<cfargument name="outputType" type="string" required="false" default="flashPaper" />
<cfset var myCfc = structNew()>
<cfset var myExplorer = createObject("component","CFIDE.componentutils.cfcexplorer")>
<cfset var cfcDocument = "">
<cfset var cfceData = "">

<cfset myCfc.name = arguments.cfcType>
<cfset myCfc.path = "/" & replace(myCfc.name,".","/","all") & ".cfc">

<!--- Trap CFCExplorer's output --->
<cfsavecontent variable="cfceData">
<cfoutput>#myExplorer.getcfcinhtml(myCfc.name,myCfc.path)#</cfoutput>
</cfsavecontent>

<!--- Clean up the HTML a bit... there's a lotta crap in that output stream... --->
<cfset cfceData = reReplace(cfceData,"\t*?\n","","all")>
<cfset cfceData = reReplace(cfceData,"\s{2,}",chr(10),"all")>

<!--- Switch up the output stream based on outputType argument --->
<cfswitch expression="#arguments.outputType#">
<cfcase value="html">
<!--- Return tidied HTML for cfoutputting --->
<cfreturn cfceData />
</cfcase>
<cfcase value="flashpaper,pdf">
<!--- Return !! object !! (use cfcontent to set the right mime type!!) --->
<cfdocument fontembed="true" name="cfcDocument" format="#arguments.outputType#">
<cfoutput>#cfceData#</cfoutput>
</cfdocument>
<cfreturn cfcDocument />
</cfcase>
<cfdefaultcase>
<cfthrow message="Invalid data for argument outputType: #arguments.outputType#"
detail="Your choices for outputType are pdf, flashpaper, or html." />

</cfdefaultcase>
</cfswitch>
</cffunction>

Search CFLib.org


Latest Additions

Raymond Compton Raymond Compton added
structBlend
19 day(s) ago

Duncan Duncan added
IsZIPUK
19 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
26 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson