Grails rendering plugin css issue

旧城冷巷雨未停 提交于 2019-11-29 15:27:21

Try setting grails.serverURL in Config.groovy to the app url (ex. grails.serverURL=http://localhost:8080/appname). The plugin resolves all relative links via this setting

It may be late with my answer but I wanted to share my experience here with rendering pdf in grails. I followed the below steps and failed over to the next until I get a pdf:

  1. Used the resource plugin in the template gsp to grab a module where css was bundled.

For example: Test.gsp

<html>
<head>
  <r:require modules="bootstapApp"/>
  <r:layoutResources/>
</head>
<body>
   ....
   <r:layoutResources/>
</body>
</html>

The above worked fine but the styles were not used in the pdf after rendering. I had to fall over to step 2.

2.Started using tag as mentioned above in the problem statement. Result: No change. I wasn't able to get the styles in the pdf. Failed over to step 3

3.Added the styles inline in the template gsp. And then I was able to apply them to the pdf. Point to note here is that if you follow step 3 and you have css like bootstrap.css then inlining them in the template will be cumbersome. Even if we add them, do not forget to put them inside the media tag. For me the below worked perfectly fine:

<style type="text/css">
@media all {
    //CSS styles goes here
}
</style>
Scott Langeberg

I shared my answer elsewhere, but I ended up just embedding the external file contents into the gsp for pdf rendering:

https://stackoverflow.com/a/32767378/1599616

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!