gpc / rendering

Provides rendering of GSPs as PDFs, JPEGs, GIFs and PNGs
http://gpc.github.com/rendering
Apache License 2.0
31 stars 45 forks source link

Won't render pdf #42

Open chrismalan opened 7 years ago

chrismalan commented 7 years ago

Grails version: 3.3.1 Rendering plugin: 2.0.3 To duplicate, create a Grails project with one class called Person with three String attributes: name, surname, emailAddress. At the bottom of the show view I have this: <g:link class="edit" action="pdfThis" resource="${this.person}">Pdf This</g:link> The method in the controller is this:

def pdfThis(Long id){
        def person = Person.get(id)
        if(person){
            pdfRenderingService.render(template: "/templates/pdf/person", model: [person: person], controller: "person", response) // this is line 105
        }
    }

I notice that def pdfRenderingService does not work anymore. One has to have: grails.plugins.rendering.pdf.PdfRenderingService pdfRenderingService in the controller.

This is the template, called _person.gsp, in views/templates/pdf/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html>
    <head>
        <title>A PDF Document</title>
    </head>
    <body>
        <h1>${person?.name} ${person?.surname}</h1>
        <p>
            Your email address: ${person?.emailAddress}
        </p>
    </body>
 </html>

These are the exceptions:

java.lang.reflect.InvocationTargetException: null
        at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:211)
        at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:188)
        at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
        at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
        at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
        at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: null
        at java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1337)
        at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1197)
        at java.beans.Introspector.getBeanInfo(Introspector.java:426)
        at java.beans.Introspector.getBeanInfo(Introspector.java:173)
        at grails.plugins.rendering.document.RenderEnvironment.init(RenderEnvironment.groovy:31)
        at grails.plugins.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:68)
        at grails.plugins.rendering.document.RenderEnvironment.with(RenderEnvironment.groovy:60)
        at grails.plugins.rendering.document.XhtmlDocumentService.generateXhtml(XhtmlDocumentService.groovy:65)
        at grails.plugins.rendering.document.XhtmlDocumentService.createDocument(XhtmlDocumentService.groovy:35)
        at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:36)
        at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:35)
        at grails.plugins.rendering.RenderingService.render(RenderingService.groovy:65)
        at rendering.PersonController.pdfThis(PersonController.groovy:105)

I have no idea what is null and why it is null. Everything I am responsible for is there and is not null.

chrismalan commented 7 years ago

I have gone directly to the IText and Flying Saucer libraries and everything works. Rendering was removed as a dependency. It was simpler than I had thought.

oscdanrm commented 6 years ago

did you have any solution to this problem?

jnunderwood commented 6 years ago

I had to add the following line to build.gradle:

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