CFLib.org – Common Function Library Project

cfcToPrinter(cfcType[, outputType])

Last updated August 30, 2005

author

Jared Rypka-Hauer

Version: 1 | Requires: CF7 | 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 Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson