【发布时间】:2017-06-26 07:34:54
【问题描述】:
我正在寻找在我的由html2pdf library 生成的PDF 中添加图片。
到目前为止,我还没有找到办法。
我的函数看起来像:
@login_required
def Generate_PDF(request, id) :
personne = get_object_or_404(Individu, pk=id)
data = {"personne" :personne}
template = get_template('raw.html')
html = template.render(Context(data))
result = StringIO.StringIO()
path = Global_variables.Individu_path.path + filename
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("utf-8")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return HttpResponse('We had some errors<pre>%s</pre>' % escape(html))
在我的RawFile.html 中,我添加:
<body>
<img class="logo" src="{% get_static_prefix %}{{ mytheme }}/images/logo.jpeg" />
<h2 align="center"> <font size="6"> Fiche d'Identification - INDIVIDU</font></align> </h2>
<br></br>
<br></br>
{% block content %}
{% if personne.Image %}
<img src='./19312STRASBOURG-855525.jpg'/>
{% endif %}
<h3 align="left"> N° Identification {{personne.NumeroIdentification}} </align> </h3>
<h3 align="left"> Au nom de {{personne.Prenom}} {{personne.Nom}}</align> </h3>
...
</body>
如何在我的 PDF 中添加我的徽标和另一张图片?我搜索了不同的方法来做到这一点。没有一个工作。
谢谢
【问题讨论】: