Piyusha Jadhav
Piyusha Jadhav

Reputation: 141

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 ?

Upvotes: 2

Views: 3768

Answers (2)

Piyusha Jadhav
Piyusha Jadhav

Reputation: 141

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.

Upvotes: 0

Joshua Moore
Joshua Moore

Reputation: 24776

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

Upvotes: 3

Related Questions