Skip to content

Instantly share code, notes, and snippets.

@mertsalik
Created February 20, 2018 11:25
Show Gist options
  • Save mertsalik/251874fa92ec5a0f35799b349da8f0dc to your computer and use it in GitHub Desktop.
Save mertsalik/251874fa92ec5a0f35799b349da8f0dc to your computer and use it in GitHub Desktop.
from weasyprint import HTML
from io import BytesIO
def convert_html_to_pdf(html_string):
"""
:param html_string: rendered invoice html
:return: bytes array
"""
with BytesIO() as byte_io:
HTML(string=html_string).write_pdf(byte_io)
return byte_io.getValue()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment