简体   繁体   English

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

[英]grails unable to generate PDF using rendering plugin

I am trying to render html file to pdf using rendering plugin, my controller method is, 我正在尝试使用渲染插件将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])
}

And my _download.gsp file is, 我的_download.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>

I have added following dependencies in BuildConfig.groovy file 我在BuildConfig.groovy文件中添加了以下依赖项

compile ":rendering:1.0.0"

I received following stack-trace, 我收到了以下堆栈跟踪,

| 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

Note Update: The same code base works with grails version 2.2.4, problem only seen in grails version 2.5.0 注意更新:相同的代码库适用于grails版本2.2.4,此问题仅在grails版本2.5.0中可见

Don't know if you're still looking for an answer, but adding 不知道您是否还在寻找答案,但要添加

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

as a dependency for your project solves this. 作为项目的依赖关系可以解决此问题。

See https://github.com/gpc/rendering/issues/17 参见https://github.com/gpc/rendering/issues/17

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM