渲染PDF不适用于prod环境 [英] Rendering PDF not working on prod environment

查看:125
本文介绍了渲染PDF不适用于prod环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常奇怪的问题,即渲染PDF在任何地方都能正常工作,但不能用于生产。开发人员和测试环境没有问题,但prod无法处理它。现在唯一的变化是:比上一场战争更高的Grails版本( 2.1.0 - > 2.3.8 [但是这个改变已经在大约2个月前被引入到测试环境中,并且所有问题都已经解决了]),而几乎没有升级插件,尤其是

I have a very strange problem with rendering PDF working everywhere, but not on prod. Developer and test environments are working without problems, but prod just can't handle it. The only changes that are now on prod: higher Grails version than the last war (2.1.0->2.3.8 [but this change has been introduced to the test environment ~2 months ago and all the problems were resolved then]) with few upgraded plugins, especially

compile ":rendering:0.4.3"

更改为

compile ":rendering:1.0.0"

Stacktrace我得到prod:

Stacktrace I get on prod:

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)

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

My ReportController method for generating pdfs (nothing's really happening here and, yes, pdfShow file starts with an underscore):

    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文件中声明的字体问题。

I have already done quite some research and found indications that it might be the problem with fonts declared in .css file which is used by the pdf template.

嗯,这是.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;
}

这些字体都在测试和产品上。

And the fonts are there, both on test and prod. And did not change their location.

我试图降级渲染插件回到 0.4 .3 ,但它不起作用,抱怨没有可用的类:

I have tried downgrading rendering plugin back to 0.4.3, but it didn't work, complaining about not available classes:

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 { ... 也无效。

你有什么想法可能是错的?

Do you have any idea what could be wrong?

推荐答案

解决问题的方法是将一行添加到 Config.groovy

The thing which solved the problem, was adding one line to the Config.groovy:

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

我们在测试开发环境,但之前,使用Grails 2.1.0它仍然可以工作。

We had this line in the test and development environments, but before, with Grails 2.1.0 it worked anyway.

这篇关于渲染PDF不适用于prod环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆