Grails渲染PDF插件不起作用,简单的例子



我正在尝试使用渲染插件将一个简单的模板保存为 pdf,但无论我尝试什么,我都无法让它工作。 我所需要的只是让它在服务器上的文件系统中保存一个文件并重定向到不同的页面。

目前,pdf模板不需要任何参数,因为它只是打印hello world。 一旦我开始工作,我将尝试添加一些数据。

我收到错误,说如果没有附加"/",我需要指定控制器。 但是我尝试添加它无济于事。 另外,我不明白它需要哪个控制器,因为我尝试指定声明此操作的控制器。

有人可以看看这个并告诉我我做错了什么吗?

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

我在控制台中收到以下错误消息:

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)

你看过FileOutputStream文档吗?没有write(OutputStream)方法。

试试fos.write(bytes.toByteArray()) . 此外,bytes.writeTo(fos)可能有效。

最新更新