2

I have an html template which I need to render as a .PDF and then save that pdf file on server. I'm using "rendering" plugin of grails. I'm able to render file as PDF but I don't understand how to save it on server location and not on user's system. Can anybody please help me ?

2 Answers 2

3

The pdfRenderingService provided by the plugin allows you to call render and get back an OutputStream. Using that output stream you can write that to a file on your server. The documentation explains the basics of using the service.

Your code may look something like this:

new File("report.pdf").withOutputStream { outputStream -> outputStream << pdfRenderingService.render(template: '/report/report', model: [serial: 12345]) } 
Sign up to request clarification or add additional context in comments.

4 Comments

Okk.. Well actually I'm not that good with file writing and all. How to provide a dir path to grails program where it can download and save pdf file. And this whole process would be called in a scheduler, so can we do this automatically ?
That's difficult to answer since you haven't given any examples of what you have already tried/written. Stackoverflow is used to answer specific programming questions.
Hey actually your answer gave me a hint how to do it. But I used different plugin.
@JoshuaMoore Is it possible to use an html/gsp string for the template field instead of a view directory?
0

Well, actually I changed my plugin. Got Wkhtmltopdf plugin of grails more helpful. you can find it here -- https://github.com/quorak/grails-wkhtmltopdf

Also instructions regarding using this plugin you can find on the same link or here --

[https://github.com/quorak/grails-wkhtmltopdf]

Using this you can get "bytes" which you can write to file system.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.