I need a really stupid thing but I'm stuck. I need basically to render a gsp page and save the rendering locally on server side inside a folder I created under web-app/.
Basically the output of this:
render(view: "report-test")
must be saved in a file as example report-test.html inside a folder locate in web-app/report/
any good advice?
thanks a lot
UPDATE - EXPLANATION Thanks a lot to everyone. Let me explain what I'm trying to do, hopefully there is a better solution. I bet there is, I'm still a newbie in grails. I'm trying to print a report using print-css and Price software that helps me to create a pdf. So my idea was to create the HTML file dynamically using a gsp, and followinf the print-css rules then save it locally on the server side then execute a command (with Price) that create my pdf file and return back the pdf file to the browser.
UPDATE I need to use css but not to be used inside the html but as part of Price software command. http://www.princexml.com/ So basically the gps rendered is an html without any css applied, then when I run the command to create the pdf I specify the css file to apply. As example:
prince -s pdf-styles.css book.html builds/book.pdf
UPDATE/2 - CLOSE
thanks to shutgunNinja see his pseudo code in his post below, here the code I'm going to use:
class YourController {
def printHtml() {
render(view: "report-test")
}
def buildReport() {
String basePath = applicationContext.getResource("/").getFile().toString()
def url = new URL("http://localhost:8080/PrjName/report/printHtml)
def data = url.getText()
def file = new File("${basePath}/reportFolder/report.html")
file.createNewFile()
FileUtils.writeStringToFile(file, data)
}
}
So as wrote before by shutgunNinja, I call buildReport() which call the URL to get the html file. I'd like to add few advices:
- Be careful if you are using some security framework, like spring security, you must be able to call that page without auth, otherwise instead of the file you requested you see a login page
- I add the basepath var where I stored the right address to access web-app directory