grailsgrails-plugingrails-2.0

How To use Rendering plugin in grails


I am using the Rendering plugin for creating PDFs. The plugin is working fine. However, when I click on download as PDF. It redirects me to another page:

Screenshot of the other page

It gives me a result in PDF format and then it gives me an option for saving as in this image: Screenshot of saving as PDF

But what I want is when I click on the download as PDF button: Download button

That it will show me a save window directly rather than redirecting me to another page.

My code:

def renderFormPDF(Long id){
        def empinstance= emp.get(id)
        renderPdf(template:"view", model:[empinstance:empinstance, pdfRendering:true])
        
    }

Solution

  • Try this

    def renderFormPDF(Long id){
        def empinstance= emp.get(id)
    
        response.setContentType("application/pdf")
        response.setHeader("Content-Disposition", "attachment; filename=fileName.pdf")
    
        renderPdf(template:"view", model:[empinstance:empinstance, pdfRendering:true])
    }