0

I am trying to render html file to pdf using rendering plugin, my controller method is,

 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,

<%@ 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

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Currently I implemented pdfbox for this purpose. But I will try your solution and if it works I will accept your answer. May be in a couple of days.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.