weasyprint doesn't apply css style in output file

9.9k views Asked by At

I'm trying to output a pdf from an html page using a python script with weasyprint library. I got the output as a pdf file, but the pdf page is not styled however I'm using bootstrap css style. This is a snippet of my code:

HTML('./result.html').write_pdf('./result.pdf', stylesheets=[CSS(filename='./bootstrap.css')])

result.html file:

<html>
<head>
    <link rel="stylesheet" href="bootstrap.css">
</head>
<body>
<h1 class='text-primary'>Title</h1>
</body>
</html>

WeasyPrint version: 0.40

1

There are 1 answers

0
fsalazar_sch On

Assuming your routes are correct, you have to remove the 'filename=' in the CSS like:

html = HTML('./result.html') #html file location
html.write_pdf(target='./result.pdf', stylesheets=[CSS('bootstrap.css')])