pdfgrailspluginsrenderingpdf-rendering

Render HTML or GSP as a PDF and save it on server


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 ?


Solution

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