3

我正在尝试使用渲染插件将一个简单的模板保存为 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)
4

1 回答 1

2

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

试试fos.write(bytes.toByteArray())。此外,bytes.writeTo(fos)可能工作。

于 2012-06-18T15:47:20.117 回答