2015-08-06 2 views
0

Я пытаюсь сделать HTML-файл в формате PDF с помощью рендеринга плагин, мой метод контроллера,Grails не в состоянии генерировать 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]) 
} 

И мой файл _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> 

я добавил следующие зависимости в 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

Не знаю, если вы все еще ищете ответ, но добавление

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

как зависимость для вашего проекта решает это.

Смотреть https://github.com/gpc/rendering/issues/17

+0

В настоящее время я реализовал pdfbox для этой цели. Но я попробую ваше решение, и если это сработает, я приму свой ответ. Может быть, через пару дней. – Balkrishna

Смежные вопросы