No one else encountered this? Really?

The solution I came up with was to send PDF processing to another server 
running CF7. That server processes the CFDocument tag and sends back the file. 
Here's the custom tag I came up with to hand off and receive the data.

<!---
        TAG NAME AND PURPOSE
                tag_pdfball by Jordan Roher, CorpDirect Agents, Inc.
                Send a ColdFusion file to another server to be processed into a 
PDF.
                Then store and return the location of said PDF.
        
        HISTORY
                March 30, 2009  Created
                
        CONTACT
                Jordan Roher
                jordanro...@corpdirect.com
        
        PARAMETERS
                INPUT
                        name                                                    
        required        type            notes
                        
---------------------------------------------------------------------------
                        document                                                
        yes                     string          The saved content you want to 
generate as a PDF
                        server                                                  
        yes                     string          Full address to server and file 
you want to send this file to.
                        timeout                                                 
        no                      number          How long, in seconds, should 
the server wait to get that PDF? Defaults to 60 seconds.
                        tempFolder                                              
        no                      string          Where should I put the 
temporary file I generate and the one received from the server? Defaults to 
caller.email_attach_path.
        
                OUTPUT
                        name                                                    
        always          type            notes
                        
---------------------------------------------------------------------------
                        pdfball.okay                                            
yes                     boolean         Did it work?
                        pdfball.file                                            
no                      string          If successful, absolute path to the 
file received
                        pdfball.error                                           
no                      string          If not successful, the error message 
returned from the other server

--->
<cfif ThisTag.executionMode IS "start">
        <cfscript>
                // Constants
                        null = "";                              dot = ".";      
                        slash = "/";
                        backslash = "\";                semicolon = ";";        
        dash = "-";
                        star = "*";                             space = " ";    
                all = "all";
                        one = "one";                    comma = ",";            
        tab = chr(9);
                        newline = chr(13);              newline2 = chr(10);     
        amp = "&";
                
                // Parameter collection and processing
                        universalParameters = "
                                        document
                                ,       timeout
                                ,       tempFolder
                                ,       server
                        ";
                        
                // Remove newlines, spaces and tab characters
                        universalParameters = REReplace(universalParameters, 
"[\s]", null, all);
                
                // Populate variables with null
                        for(i = 1; i LTE ListLen(universalParameters); i = i + 
1) {
                                if(NOT StructKeyExists(attributes, 
ListGetAt(universalParameters, i))) {
                                        StructInsert(attributes, 
ListGetAt(universalParameters, i), null);
                                }
                        }
                
                // General error checking
                        errorMessage = null;
                        
                        if(attributes.document IS null) {
                                errorMessage = "Document to generate not 
specified";
                        }
                        
                        if(attributes.timeout IS null OR NOT 
IsNumeric(attributes.timeout)) {
                                attributes.timeout = 60;
                        }
                        
                        if(attributes.tempFolder IS null AND 
IsDefined("caller.email_attach_path")) {
                                attributes.tempFolder = 
caller.email_attach_path;
                        }
                        if(NOT DirectoryExists(attributes.tempFolder)) {
                                errorMessage = "Temporary folder not 
accessible";
                        }
                        
                        if(attributes.server IS null) {
                                errorMessage = "Other server not specified";
                        }
        </cfscript>
        
        <cfif errorMessage IS NOT null>
                <cfabort showerror="#errorMessage#">
        </cfif>
        
        <!--- Remove the bangs in front of the CF tags --->
        <cfset attributes.document = Replace(attributes.document, "<!cf", 
"<cf", all)>
        <cfset attributes.document = Replace(attributes.document, "</!cf", 
"</cf", all)>
        
        <!--- Save it as a file --->
        <cfset tempFile = CreateUUID() & ".cfm">
        <cfloop condition="FileExists('#attributes.tempfolder##tempFile#')">
                <cfset tempFile = CreateUUID() & ".cfm">
        </cfloop>
        <cffile action="WRITE" file="#attributes.tempFolder##tempFile#" 
output="#attributes.document#" addnewline="No" fixnewline="No">
        
        <!--- Send this file to another server and wait for the response --->
        <cfhttp url="#attributes.server#" method="POST" getasbinary="auto" 
timeout="#attributes.timeout#">
                <cfhttpparam type="FILE" name="processPage" 
file="#attributes.tempFolder##tempFile#">
        </cfhttp>
        
        <!--- Get our return structure ready --->
        <cfset pdfBall = StructNew()>
        
        <!--- The response should be a binary file --->
        <cfif IsBinary(cfhttp.fileContent)>
                <!--- Yay, it worked. Huzzas all around.--->
                <cfset pdfBall.okay = true>
                
                <!--- Save that PDF as a file --->
                <cfset tempFilePDF = CreateUUID() & ".pdf">
                <cfloop 
condition="FileExists('#attributes.tempfolder##tempFilePDF#')">
                        <cfset tempFilePDF = CreateUUID() & ".pdf">
                </cfloop>
                <cffile action="WRITE" 
file="#attributes.tempFolder##tempFilePDF#" output="#cfhttp.fileContent#" 
addnewline="No" fixnewline="No">
                
                <!--- Record the name and away we go --->
                <cfset pdfBall.file = "#attributes.tempFolder##tempFilePDF#">
        <cfelse>
                <!--- Something blew up. File an error report, maybe? --->
                <cfset pdfBall.okay = false>
                
                <!--- Here's what happened, ossifer. --->
                <cfset pdfBall.error = cfhttp.fileContent>
        </cfif>
        
        <!--- Either way, delete the original file --->
        <cffile action="DELETE" file="#attributes.tempFolder##tempFile#">
        
        <cfset caller.pdfBall = pdfBall>
<cfelse>
        <cfexit>
</cfif> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:321262
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to