Search code examples
intellij-ideagrailsgroovybootstrap-4bootstrap-5

How to use bootstrap.css to generate PDF in Grails


I am working on a Grails-5 project. To export data in PDF format I am using rendering plugin. Everything works well but when I include the bootstrap.css in the page header e.

Caused by: java.lang.ClassCastException: org.xhtmlrenderer.render.BlockBox cannot be cast to org.xhtmlrenderer.newtable.TableBox

Below is the code. enter image description here


Solution

  • I doubt this is going to work out of the box. It looks like XHTMLlRenderer library has limitations on CSS it recognizes, and Bootstrap is going to be super modern compared to what XHTMLRenderer supports. It appears that it doesn't understand how to render say a TableBox vs a BlockBox. So I suspect doing this in CSS is not supported with XHTMLRenderer.

    .someClass {
       display: table;
    }
    

    I know HTML tables are supported with XHTMLRenderer because I use them extensively for PDF creation, but support for taking a non-table tag like div and setting it's display to table is questionable at best.

    You'll probably have to trim out sections from bootstrap with the rules you with use and create a subset of bootstrap for usage.