Grails呈现插件在部署时不会呈现图像 [英] Grails rendering plugin does not render images when deployed

查看:127
本文介绍了Grails呈现插件在部署时不会呈现图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用grails渲染插件生成pdf。
在开发过程中,我将包含src的标签的图像包含在服务器上的图像上。它可以很好地工作,但在应用程序部署时不再适用。图像只是消失。

我通过模板重写,所以当我在gsp中调用这个模板时,它是可以的(即,我看到html版本的pdf与图像),BU当我的控制器中使用renderPdf,没有图像。



再次只在部署的应用程序(战争),而不是在开发。 b
$ b

任何提示?



编辑:根据流行的要求,这里是代码:



_pdf.gsp文件可以像

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Strict // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> 
< html>
< head />
< body>
< img src =path / to / image.jpg/>
< / body>
< / html>

控制器的相关部分是

  def pdf = {
renderPdf(template:/ file / pdf,filename:myfile.pdf)
}


解决方案

我一直在寻找这两个令人沮丧的日子,并尝试了很多事情。我的建议是,他们在文档中给出的建议是坚持内嵌图像。我的意思是定义图像的字节形式。您不会后悔,并且您可以确定渲染插件可以与其他插件(如UI性能和资源)相媲美。



首先创建文件对象,如下所示:

  def paid = new File(ApplicationHolder.application.parentContext.servletContext.getRealPath(/ images / paid.jpg))

然后将文件的字节传递到模型中
$ b $ pre $ renderPdf(模板:invoiceTemplate,model:[paidBytes:paid.bytes ])

现在在您的pdf模板中使用以下标记:

 < rendering:inlineJpeg bytes =$ {paidBytes}/> 

如果您没有依赖性问题,那么您应该设置。
如果您遇到像我一样的依赖项问题,并提到 这里 ,然后查看您拉入的iText版本。

I am generating a pdf using grails rendering plugin. When in development, I include images using tag with src to an image on server. It works fine, but not anymore when the app is deployed. The images just disappear.

I am redering through a template, so when i call this template to in gsp, it is ok (ie i see the html version of the pdf with the images), bu when called in my controller using renderPdf, no images.

Again only in deployed app (war), not in development.

Any hints?

EDIT: Under popular request here is the code:

the _pdf.gsp file can be as simple as

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head/>
  <body>
    <img src="path/to/image.jpg"/>
  </body>
</html>

the relevant part of the controller is

def pdf={
     renderPdf(template: "/file/pdf", filename: "myfile.pdf")
}

解决方案

I have been looking at this for two frustrating days, and have tried many things. My advice, and it is the advice that they do give in the documentation is to stick to inline images. By that I mean define the image in its byte form. You won't regret it, and you will be sure the rendering plugin will play nice with other plugins like ui-performance and resources.

First create the file object like so

def paid = new File(ApplicationHolder.application.parentContext.servletContext.getRealPath("/images/paid.jpg"))

then pass in the bytes of the file into the model

renderPdf(template:invoiceTemplate, model:[paidBytes:paid.bytes])

Now in your pdf template use the following tag:

<rendering:inlineJpeg bytes="${paidBytes}" />

If you have no dependency issues then you should be set. If you do run into dependency issues like I did and noted HERE, then look at the version of iText your pulling in.

这篇关于Grails呈现插件在部署时不会呈现图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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