Python中文
首页
教程
问答
标签
搜索
登录
注册
使用Python/Flas将html转换为pdf
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我想用Python+Flask从html生成pdf文件。为此,我使用xhtml2pdf。这是我的代码:</p> <pre><code>def main(): pdf = StringIO() pdf = create_pdf(render_template('cvTemplate.html', user=user)) pdf_out = pdf.getvalue() response = make_response(pdf_out) return response def create_pdf(pdf_data): pdf = StringIO() pisa.CreatePDF(StringIO(pdf_data.encode('utf-8')), pdf) return pdf </code></pre> <p>在此代码文件中正在动态生成。但是!xhtml2pdf在CSS中不支持许多样式,因为正确标记页面有一个大问题。我发现了另一种乐器(wkhtmltopf)。但当我写下这样的话:</p> <pre><code>pdf = StringIO() data = render_template('cvTemplate1.html', user=user) WKhtmlToPdf(data.encode('utf-8'), pdf) return pdf </code></pre> <p>引发错误:</p> <pre><code>AttributeError: 'cStringIO.StringO' object has no attribute 'rfind' </code></pre> <p>我的问题是如何在Flask中使用wkhtmltopdf(动态生成文件)将html转换为pdf?</p> <p>提前谢谢你的回答。</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>你试过使用<a href="http://weasyprint.org/" rel="noreferrer">WeasyPrint</a>的<a href="https://pythonhosted.org/Flask-WeasyPrint/" rel="noreferrer">Flask-WeasyPrint</a>吗?他们的网站上有很好的例子,所以我不在这里复制它们。</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
VirtualEnvRapper错误:路径python2(来自python=python2)不存在
5 回答
virtualenvs上的pyinstaller,没有名为导入错误的模块
1 回答
virtualenvs是否可以退回到用户包而不是系统包?
3 回答
virtualenvwrapper CentOS7
1 回答
virtualenvwrapper IOError:[Errno 13]权限被拒绝
9 回答
virtualenvwrapper mkproject和shell在windows中的启动问题?
5 回答
virtualenvwrapper mkvirtualenv不工作但没有错误
7 回答
Virtualenvwrapper python bash
2 回答
virtualenvwrapper:“workon”何时更改到项目目录?
5 回答
virtualenvwrapper:mkvirtualenv可以工作,但是rmvirtualenv返回bash:没有这样的文件或目录
8 回答
virtualenvwrapper:virtualenv信息存储在哪里?
9 回答
virtualenvwrapper:命令“python设置.pyegg_info“失败,错误代码为1
9 回答
virtualenvwrapper:如何将mkvirtualenv的默认Python版本/路径更改为ins
8 回答
Virtualenvwrapper:模块“pkg_resources”没有属性“iter_entry_points”
9 回答
Virtualenvwrapper:没有名为virtualenvwrapp的模块
10 回答
Virtualenvwrapper.bash_profi的正确设置
4 回答
Virtualenvwrapper.hook:权限被拒绝
4 回答
virtualenvwrapper.sh:fork:资源暂时不可用Python/Djang
9 回答
Virtualenvwrapper.shlssitepackages命令不工作
7 回答
Virtualenvwrapper.sh函数在bash sh中不可用
8 回答