Last active
August 29, 2015 14:12
-
-
Save staticnull/27a4a1aa472738181faf to your computer and use it in GitHub Desktop.
Report Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo | |
class ReportController { | |
/** | |
* Generate PDF report | |
* | |
* phantomjs ./scripts/phantomjs/rasterizestdout.js <url of report> <name>.pdf <url of footer> | |
* | |
* http://stackoverflow.com/questions/12403817/phantomjs-pipe-input/17286691#17286691 | |
* Need this link in rasterize.js: | |
* page.render('/dev/stdout', { format: 'pdf' }); | |
*/ | |
def index(Long profileId, Long evaluationId, Long groupId, String reportName) { | |
String serverURL = grailsApplication.config.grails.serverURL | |
String phantomPDFScript = grailsApplication.config.grails.phantomPDFScript | |
log.trace "Configured serverURL: ${serverURL}" | |
def reportUrl = "${serverURL}/index.html#/profile/${profileId}/evaluation/${evaluationId}/group/${groupId}/report" | |
log.trace "Report URL: ${reportUrl}" | |
def footImageUrl = "${serverURL}/images/footer-no-logo.jpg" | |
log.trace "Footer Image URL: ${footImageUrl}" | |
List cmd = ['/usr/local/bin/phantomjs', "${phantomPDFScript}", "${reportUrl}/${reportName}", "${reportName}.pdf", "${footImageUrl}"] | |
log.trace "PhantomJS command: ${cmd}" | |
// https://grails.org/FAQ#Q: Can I use the render method to return a binary file to the client? | |
response.contentType = "application/pdf" | |
def process = cmd.execute() | |
process.consumeProcessOutput(response.outputStream, response.outputStream) | |
process.waitFor() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment