https://json2html.com/

    1. 安装 json2html
    2. 安装 pdfkit(需要 wkhtmltox) ``` from json2html import * import json import tempfile

    class PdfConverter(object):

    1. def __init__(self):
    2. pass
    3. def to_html(self, json_doc):
    4. return json2html.convert(json=json_doc)
    5. def to_pdf(self, html_str):
    6. return pdfkit.from_string(html_str, None)

    def main(): stowflw = { “data”: [ { “state”: “Manchester”, “quantity”: 20 }, { “state”: “Surrey”, “quantity”: 46 }, { “state”: “Scotland”, “quantity”: 36 }, { “state”: “Kent”, “quantity”: 23 }, { “state”: “Devon”, “quantity”: 43 }, { “state”: “Glamorgan”, “quantity”: 43 } ] }

    1. pdfc = PdfConverter()
    2. with open("sample.pdf", "wb") as pdf_fl:
    3. pdf_fl.write(pdfc.to_pdf(pdfc.to_html(json.dumps(stowflw))))

    ```