Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails rendering plugin does not render images when deployed

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")
}
like image 629
fixitagain Avatar asked Apr 15 '26 00:04

fixitagain


1 Answers

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.

like image 136
34m0 Avatar answered Apr 19 '26 01:04

34m0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!