Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grails rendering pdf plugin not working, simple example?

I am trying to save a simple template to pdf using the rendering plugin, but I cannot get it to work no matter what I try. All I need is for it to save a file within the file system on the server and redirect to a different page.

At the minute the pdf template does not need any parameters as it just prints hello world. Once I get this working I will attempt to add some data.

I am getting errors saying I need to specify a controller if no '/' is appended. But I have tried adding this to no avail. Plus I don't understand which controller it needs as I have tried specifying the controller this action is declared.

Can someone please have a look at this and tell me what I'm doing wrong?

 RenderingService pdfRenderingService


 def displayPDFSummary = {
        ByteArrayOutputStream bytes = pdfRenderingService.render(template: "_pdfTemplate", controller:"RSSCustomerOrder", model: [origSessionId:params.origSessionId])
        def fos= new FileOutputStream('NewTestFile.pdf')
          fos.write(bytes)
          fos.close()

        render(template: "_pdfTemplate", params: [origSessionId:params.origSessionId])
    }

I am getting the following error messages in the console:

groovy.lang.MissingMethodException: No signature of method: java.io.FileOutputStream.write() is applicable for argument types: (java.io.ByteArrayOutputStream)

(Then prints contents of template...)

Possible solutions: write([B), write(int), write([B), write(int), wait(), wait(long)
like image 641
BON Avatar asked Nov 26 '25 14:11

BON


1 Answers

Did you look at the FileOutputStream docs? There's no write(OutputStream) method.

Try fos.write(bytes.toByteArray()). Also, bytes.writeTo(fos) may work.

like image 102
Kaleb Brasee Avatar answered Dec 01 '25 01:12

Kaleb Brasee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!