Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force weasyprint to use the colors in PDF?

When I use

$ weasyprint table.html table.pdf

on https://jsfiddle.net/MartinThoma/0hL29mcc/ it generates a PDF which looks like this:

enter image description here

As you can see, the heading is black, not red. Also, the table is not striped anymore.

Somehow weasyprint removes all colors. How can I prevent this behaviour / keep the colors? (I don't necessarily need to use weasyprint, but I don't know any better alternative)

I use WeasyPrint version 0.40.

What I've tried

  • pandoc table.html -o table.pdf: Does not apply CSS page rotation; does not apply CSS
  • wkhtmltopdf table.html out.pdf: Does not apply CSS page rotation; (but applies some CSS - not the color, though)
  • import pdfkit;pdfkit.from_file('table.html', 'outpdfkit.pdf'): Does not apply CSS page rotation (looks the same as wkhtmltopdf)
like image 342
Martin Thoma Avatar asked Sep 18 '25 21:09

Martin Thoma


1 Answers

The main problem is that Bootstrap 3 contains the following:

@media print{
    *,:after,:before {
        color:#000!important;
        text-shadow:none!important;
        background:0 0!important;
        -webkit-box-shadow:none!important;
        box-shadow:none!important
    }
}

So weasyprint is actually behaving as intended. Removing this leads to the expected results.

like image 83
Martin Thoma Avatar answered Sep 20 '25 11:09

Martin Thoma