WeasyPrint recipe

08-14-2017 09:35

We've just released yet another recipe doing pdf rendering based on html conversion. The new recipe package is called jsreport-weasyprint-pdf and uses WeasyPrint library to process the conversion.

Why another recipe doing the same job as already existing wkhtmltopdf, phantom-pdf or electron-pdf? Because there is no clear winner which technology is the best and we want to give you the opportunity to choose the one which fits to you the most.

The WeasyPrint excels in support for css page rule. This allows you to use css standard to define page header or footer. The suport for this is very limited in other recipes and we believe that the new jsreport-weasyprint-pdf can fill this hole.

The header and footer defined using css page rule can be as simple as this. This is were the WeasyPrint shines.

@page {
    margin: 1cm 1cm;   
    @top-center {
        content: "My report header";
        vertical-align: bottom;
        border-bottom: 0.5pt solid 
    }
    @bottom-right {
        content: "Page " counter(page)
                 " of " counter(pages) 
    }  
}


The biggest downside of the WeasyPrint library is that it doesn't support javascript evaluation. This means no chart libraries and so on. But wait! The jsreport recipe is so smart that it the first evaluates javascript using phantomjs before it starts printing. This means that there should be no breaking barier for switching already existing templates into it.

weasyprint

Please check the installation instructions in the repository readme and give us feedback how does it work for you.