0

I am trying to use bootstrap.css to style a pdf that is being generated by the grails rendering plugin. The pdf is generated fine but none of the css styling is being applied.

Have been searching for an answer to this for the past couple of days and am getting nowhere.

css background is not working when convert template into pdf using rendering plugin

Grails rendering plugin css issue

All the answers suggest that the solution is to make sure grails.serverURL is set correctly in Config groovy.

Currently running on development machine running in secure mode so I have set grails.serverURL="https://localhost:8443/" and have also tried different variations of this.

Template code for .gsp file is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <title>Invoice</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

        <style  type="text/css">
            @page {
            size: A4 landscape;

            }

        </style>

        <link rel="stylesheet" href="${resource(dir: 'css', file: 'bootstrap.css')}"/>
        <r:layoutResources/>
    </head>
    <body>
    <div class="content">
        <div class="well">
        <p class="pull-right">Invoice: ${companyName.encodeAsHTML()}</p></div></div>
        <r:layoutResources/>
    </body>
</html> 

Any suggestions would be greatly appreciated.

Community
  • 1
  • 1

2 Answers2

0

Did you tried inline css for the background image?,I think it should work, although I didn't tried it, but should work.

Saurabh Dixit
  • 633
  • 4
  • 16
  • Hi Saurabh inline css does work but I need to use a lot of the formatting supplied in bootstrap so that isn't really an option for me. Thanks for the reply. – Ashley Callaghan May 21 '13 at 15:32
0

Since you are relying on the grails.serverURL setting, you should be able to fully utilize the flavor of resources plugin.

If you declare the bootstrap-app.css or bootstrap.min.css as application resources modules, you should be able to require them in the gsp as shown below. You can try this approach otherwise you have to use the inline css as I had mentioned in the earlier questions you referred. I had to stick with inline css because I was not referring to grails.serverURL for host. My application used an host override in different environments.

//ApplicationResources.groovy
bootstrap {
    //resource url:'/css/bootstrap-app.css'
    resource url:'/css/bootstrap.min.css'
}

//GSP
<head>
    <title>Invoice</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <r:require modules="bootstrap"/>
    <r:layoutResources/>
</head>
<body>
<div class="content">
    <div class="well">
    <p class="pull-right">Invoice: ${companyName.encodeAsHTML()}</p></div></div>
    <r:layoutResources/>
</body>
dmahapatro
  • 49,365
  • 7
  • 88
  • 117
  • Thanks for the suggestion but it gives me the exact same results i.e. no css styling is applied to the rendered pdf – Ashley Callaghan May 21 '13 at 15:46
  • BTW, I have removed `@page` in my answer, you would need that in the template explicitly. In case if it is still an issue, you can try having the minified bootstrap (bootstrap.min.css) inline after removing the unwanted styles. – dmahapatro May 21 '13 at 16:24
  • Think I will have to with try going with the inline option. Thanks again for your help. – Ashley Callaghan May 21 '13 at 18:51
  • My last resort was to become a professor [here](http://stackoverflow.com/a/15650855/2051952) and let know how much hair I pulled from my head making it to work. :) – dmahapatro May 21 '13 at 19:32
  • Haha I can imagine :) Thanks again for all your help. In the end I got it working by inlining the minified bootstrap after removing the unwanted styles. – Ashley Callaghan May 22 '13 at 17:51