Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于在python2.7中使用html2pdf将html转换为pdf的问题_Python_Html_Pdf_Html2pdf_Pisa - Fatal编程技术网

关于在python2.7中使用html2pdf将html转换为pdf的问题

关于在python2.7中使用html2pdf将html转换为pdf的问题,python,html,pdf,html2pdf,pisa,Python,Html,Pdf,Html2pdf,Pisa,当我呈现html时,这是正常的,但是当我将其转换为pdf时,请使用pisa: def render_html2pdf_stream_pisa(template_src, context_dict): template = get_template(template_src) context = Context(context_dict) html = template.render(context) try: result = StringI

当我呈现html时,这是正常的,但是当我将其转换为pdf时,请使用pisa:

def render_html2pdf_stream_pisa(template_src, context_dict):

    template = get_template(template_src)

    context = Context(context_dict)

    html = template.render(context)
    try:
        result = StringIO.StringIO()
        pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")),
                                dest=result,
                                encoding="UTF-8",
                                )
        if not pdf.err:
            return result.getvalue()
    except Exception,e:
        print Exception(e)

    return None
因此,pdf是半成品,不像html样式那样是完整的pdf文件


我不知道问题出在哪里

我用pdfkit解决了问题,但我找不到解决问题的方法使用pisa解决了问题使用pdfkit,但我找不到解决问题的方法使用pisa