I am using a view (together with a layout) to gene...
# box-products
f
I am using a view (together with a layout) to generate a PDF in an app running ColdBox 7. That works perfectly fine (and, by the way, is only necessary due to a Lucee bug with the script version of cfchart). Now I want to write the PDF to a file, but renderData() is streaming the generated PDF directly to the browser, and any further code is not executed. Currently, my workaround is to inject the desired filename into the prc scope, and then use that in the layout cfm. But that does not really feel like a clean solution. Any advice how to return the binary data of the PDF to the handler so it can be written to a file?
Copy code
// handler
    function generateReport( event, rc, prc ){
        prc.dataForReport = getSurveyDataForReport();
        var filename = getReportFilename();

        var result = event.renderData(data=view( layout="pdf", view="feedback/turnier" ), isBinary=true, contenttype="application/pdf", type="pdf", pdfArgs={ filename=filename } );

        fileWrite(filename, result.getRenderData().data); // <-- this line gets never executed
    }
d
As you've seen, renderData() does exactly that - it's renders the data you pass it back to the browser and bypasses the view layer altogether. Your
fileWrite()
never gets executed because the
event.renderData()
returns the data to the browser and ends the function. I think what you may be looking for is event.sendFile() and be sure to add the
.noRender()
portion to the end of it so the browser doesn't try to render the file directly. Make sure this call is the last call in your controller function as it will also end the function just like
renderData()
does.
f
Thanks for the explanation @David Belanger, appreciate it a lot. My understanding of
renderData()
so far has been that it will happily provide data without passing it directly to the browser (at least we have used it that way and now encountered the issue mentioned above where it works as you are describing it for PDFs). Anyway, the workaround does what we need, so all is well. Thanks again!