当前位置: 首页 > 知识库问答 >
问题:

grails无法使用渲染插件生成PDF

景岳
2023-03-14

我正在尝试使用渲染插件将html文件渲染为pdf,我的控制器方法是,

    def download() {
    response.contentType = 'application/pdf'
    response.setHeader("Content-disposition", "attachment; filename=\"download.pdf\"")
    def items = []
    (101..105).each { number->
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        items << [number:number, bytes:bos.toByteArray()]
    }

    renderPdf (template:'download', model:[items:items])
}

和我的下载。gsp文件为,

<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<body>
<g:each in="${items}" var="item">
    <div>This is the barcode for the number: ${item.number}</div>
    <hr/>
</g:each>
</body>
</html>

我在BuildConfig中添加了以下依赖项。groovy文件

compile ":rendering:1.0.0"

我收到以下堆栈跟踪,

| Error 2015-08-06 16:35:28,925 [http-bio-8080-exec-1] ERROR errors.GrailsExceptionResolver  - NullPointerException occurred when processing request: [GET] /wheeloflife/test/download
Stacktrace follows:
Message: null
    Line | Method
->> 1281 | getPublicDeclaredMethods in java.beans.Introspector
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1141 | getTargetMethodInfo      in     ''
|    416 | getBeanInfo . . . . . .  in     ''
|    163 | getBeanInfo              in     ''
|     31 | init . . . . . . . . . . in grails.plugin.rendering.document.RenderEnvironment
|     68 | with                     in     ''
|     60 | with . . . . . . . . . . in     ''
|     65 | generateXhtml            in grails.plugin.rendering.document.XhtmlDocumentService
|     35 | createDocument . . . . . in     ''
|     36 | render                   in grails.plugin.rendering.RenderingService
|     35 | render . . . . . . . . . in     ''
|     65 | render                   in     ''
|     59 | doCall . . . . . . . . . in RenderingGrailsPlugin$_closure3
|     18 | download                 in com.codeharmony.wheeloflife.TestController$$EPKZmnkm
|    198 | doFilter . . . . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter                 in grails.plugin.cache.web.filter.AbstractFilter
|     53 | doFilter . . . . . . . . in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|     62 | doFilter                 in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker . . . . . . .  in java.util.concurrent.ThreadPoolExecutor
|    615 | run                      in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . . . . . . . .  in java.lang.Thread

注意:相同的代码库适用于grails 2.2.4版本,这个问题只在grails 2.5.0版本中出现

共有1个答案

郑哲彦
2023-03-14

不知道您是否仍在寻找答案,但添加

runtime "org.springframework:spring-test:4.1.5.RELEASE"

作为项目的依赖项可以解决这个问题。

https://github.com/gpc/rendering/issues/17

 类似资料:
  • 问题内容: 我刚刚安装了grails渲染插件,并希望将其用于生成PDF文件。我已经创建了简单的模板,但是没有任何CSS样式即可将其导出。如果仅从grails渲染模板,则页面将在Web浏览器中显示所有样式。 所以,我的问题是-在PDF生成过程中如何正确包含CSS文件? 我的模板: 而且我的webui.css中具有样式.odd,但是它不适用于该行。 任何帮助,将不胜感激。 Edit1:我发现以以下方式

  • 我刚刚安装了grails渲染插件,并想使用它来生成PDF文件。我创建了简单的模板,但此插件不渲染检查输入元素。当我将输入写为以下内容时: 我收到以下错误消息: 当我添加结束标记时,如下所示: 我在PDF中没有任何检查元素。我不是说,我想要在交互模式下进行检查,但是,我想要一个看起来像复选框的图像

  • 我试图在grails 4中使用插件渲染:2.0.3,但我得到编译错误:

  • 问题内容: 今天遇到了这个奇怪的结果,试图在Grails 2.0.4中将对象列表呈现为JSON …(我知道我会后悔由于我鼻子底下的东西而问这个问题…… 已更新 5/26,我的预测是正确的,请参见下文:-)) 这很好用;JSON在浏览器中正确呈现… ..so为什么缩短的版本没有工作? 上面代码生成的JSON作为单行文本输出,因此我怀疑它没有被拾取,但是正确地加上了括号,这是怎么回事? [‘produ

  • 我想将视图渲染为pdf,并尝试使用Grails渲染插件2.0.3 我尝试了最简单的gsp-file开始: 在控制器中: 最后是: 我错过了什么?或者它不应该与这个版本的grails(3.2.4)一起使用? 也许有更好的插件可以使用?

  • 我想在PDF文档中嵌入HelveticaNeueLTCom-BdCn.ttf。我正在使用Grails渲染0.4.4插件生成PDF文件。我尝试遵循, 但它不起作用。