CFajaxproxy and sending content in CallbackHandler as PDF - it it possible?

Posted on 2009-02-21
Last Modified: 2012-05-06
Is it possible to do the following (CF8, ajax and cfdocument as PDF)? And if possible, any how to suggestions are appreciated!

The web user clicks on a link which fires a cfajax http post to a cfc.  The cfc creates a pdf document using cfdocument.  I have a working model for this.  Using cfdebug and the CF Ajax Logger window, I can see the content being sent back is a PDF ("info:http: CFC invocation response: %PDF-1.4").

In the past I have used a cfc to create the PDF as a physical file in a temp location and sent the HTML link to a div on the template.  The end user then clicks the link to download the file.

What I would like to do INSTEAD is push the pdf content back to the user, and have an alert to "open or save the file".  In the cfc I have the cfdocument creation of the pdf (which, as noted, works) and then:

<!--- Make the generated pdf open as a separate file (not a cfm file) --->
<cfheader name="Content-Disposition" value="attachment;filename=#variables.filename#">
<!--- generate the pdf and send to the subscriber --->
<cfcontent type="application/pdf" reset="true" variable="#toBinary(thispdf)#" />

On the client side I have the javascript:

function getpdf(){
      var instance = new pdfconn();
function UpdateResponse(response){
      //populate cfwindow?  push the pdf to the user

Is this doable?
Question by:akibasho
    LVL 27

    Accepted Solution

    i am not sure one can display pdf files in a cfwindow, but try this:

    in your cfc function save the generated pdf in a session scope var, then in the callback handler create/show cfwindow and point it to a .cfm page which will read that session var and display the pdf...

    LVL 16

    Expert Comment

    You want to use cfheader and cfcontent to stream the PDF to the browser, instead of sending the link.  Take a look at the top solution here:

    Also you may want to look at other options in the cfheader.  For instance instead of attachment you can specify inline.  Attachment will try and open the save dialog, inline will try and stream it to the browser (although depending on browsers and plugins, I don't think you can guarantee what will happen)

    Author Closing Comment

    This comment pointed me in a direction that gave the solution:  I used the cfc to set a variable identifying the records to use to produce the pdf (I wasn't able to save the pdf into a session var, and realized that wasn't necessary or desirable).  

    Then, once the cfc was called and the session set, I launched a regular window (not a cfwindow) with a command to a CF template.  In that template I did the query with the saved session var (list of ids) as an argument and created the pdf using cfdocument, then cfheader and cfcontent to serve the pdf.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
    If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
    This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
    Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now