Pregunta

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 ?

¿Fue útil?

Solución

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])
        }

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top