【问题标题】:weasyprint doesn't apply css style in output fileweasyprint 不在输出文件中应用 css 样式
【发布时间】:2020-12-22 06:46:15
【问题描述】:

我正在尝试使用带有weasyprint 库的python 脚本从html 页面输出pdf。我得到了pdf 文件的输出,但是pdf 页面没有设置样式,但是我使用的是引导 css 样式。这是我的代码的 sn-p:

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

result.html 文件:

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

WeasyPrint 版本:0.40

【问题讨论】:

    标签: python weasyprint


    【解决方案1】:

    假设您的路线是正确的,您必须删除 CSS 中的“filename=”,例如:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-17
      • 2022-08-02
      • 2016-01-27
      • 2014-09-05
      • 2018-02-14
      • 2016-09-25
      • 1970-01-01
      • 2018-09-04
      相关资源
      最近更新 更多