渲染PDF不适用于prod环境

时间:2015-10-30 07:44:41

标签: pdf grails

我有一个非常奇怪的问题,渲染PDF无处不在,但不是生产。开发人员和测试环境正常运行,但prod无法处理它。现在唯一的变化是:比上一次战争更高的Grails版本(2.1.0 - > 2.3.8 [但是这个变化已经被引入测试环境〜2个月前所有的问题都是然后解决了几个升级的插件,特别是

compile ":rendering:0.4.3"

更改为

compile ":rendering:1.0.0"

Stacktrace我开始生产:

java.lang.NullPointerException
at org.xhtmlrenderer.swing.NaiveUserAgent.getBinaryResource(NaiveUserAgent.java:228)
at org.xhtmlrenderer.pdf.ITextFontResolver.importFontFaces(ITextFontResolver.java:97)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:178)
at org.xhtmlrenderer.pdf.ITextRenderer.setDocument(ITextRenderer.java:142)
at grails.plugin.rendering.pdf.PdfRenderingService.doRender(PdfRenderingService.groovy:36)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:43)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:37)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:35)
at grails.plugin.rendering.RenderingService.render(RenderingService.groovy:65)
at GrailsMelodyGrailsPlugin$_closure4_closure16_closure17.doCall(GrailsMelodyGrailsPlugin.groovy:184)
at RenderingGrailsPlugin$_closure3.doCall(RenderingGrailsPlugin.groovy:59)
at com.my.app.ReportController$_closure8.doCall(ReportController.groovy:169)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:150)
at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:285)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:198)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:176)

我生成pdf的ReportController方法(这里没有发生任何事情,是的,pdfShow文件以下划线开头):

    def generatePdf = {
    if (!params.id) {
        throw new IllegalArgumentException("PDF Generation: an instance identifier has not been passed.")
    }
    def reportInstance = Report.findById(params.id)
    renderPdf(template: "pdfShow", model: [reportInstance: reportInstance], filename: reportInstance?.reportFilename + '.pdf')
}

我已经做了很多研究,发现可能是pdf模板使用的.css文件中声明的字体存在问题。

嗯,这是.css:

@font-face {
    src: url("../fonts/DejaVuSansCondensed.ttf");
    -fs-pdf-font-embed: embed;
    -fs-pdf-font-encoding: Identity-H;
}

@font-face {
    src: url(../fonts/DejaVuSansCondensed-Bold.ttf);
    -fs-pdf-font-embed: embed;
    -fs-pdf-font-encoding: Identity-H;
}

body {
    font-family: "DejaVu Sans Condensed", Arial, sans-serif;
}

字体在那里,无论是测试还是产品。并没有改变他们的位置。

我尝试将rendering插件降级回0.4.3,但它没有用,抱怨没有可用的课程:

plugins\rendering-0.4.3\grails-app\services\grails\plugin\rendering\document\XhtmlDocumentService.groovy: 20: unable to resolve class org.xhtmlrenderer.resource.XMLResource
(...)\plugin\rendering\pdf\PdfRenderingService.groovy: 25: unable to resolve class com.lowagie.text.pdf.BaseFont
(...)\plugin\rendering\pdf\PdfRenderingService.groovy: 19: unable to resolve class org.xhtmlrenderer.pdf.ITextRenderer
...and few others etc.

BuildConfig.groovy

中进行设置
legacyResolve true

grails.project.dependency.resolution { ...也无效。

你知道可能出现什么问题吗?

1 个答案:

答案 0 :(得分:0)

解决问题的方法是在Config.groovy添加一行:

environments {
    production {
        (...)
        grails.resources.processing.enabled = false

我们在testdevelopment环境中使用了这一行,但之前使用Grails 2.1.0它仍然有用。