Skip to content

Instantly share code, notes, and snippets.

@opalczynski
Last active September 16, 2021 16:44
Show Gist options
  • Select an option

  • Save opalczynski/99ff2dfca7498994c057853c6a6a87e4 to your computer and use it in GitHub Desktop.

Select an option

Save opalczynski/99ff2dfca7498994c057853c6a6a87e4 to your computer and use it in GitHub Desktop.
CSS adding to weasyprint
def render_pdf():
template = get_template()
rendered = template.render(**{"name": "John"})
html = weasyprint.HTML(string=rendered, base_url="/")
css = weasyprint.CSS(filename="./template.css")
with open("output/test.pdf", "wb") as f:
html.write_pdf(f, stylesheets=[css])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment