Django:使用Pisa库显示图像
我正在寻找由Django:使用Pisa库显示图像,django,html2pdf,pisa,Django,Html2pdf,Pisa,我正在寻找由html2pdf库生成的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 = templat
html2pdf库
生成的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))
如何在我的PDF中添加我的徽标和其他图片?我找到了不同的方法。没有人在工作
谢谢我找到了解决方案;)
这是我的剧本:
<h2 align="center"> <font size="6"> Fiche d'Identification - INDIVIDU</font></align> </h2>
<br></br>
<br></br>
{% block content %}
{% if personne.Image %}
<img src='/Users/Desktop/Django/DatasystemsCORE/Photos_Identifications/pictures/19312STRASBOURG-614245.jpg' class="img-responsive"/>
{% endif %}
和我的HTML文件:
Fiche d'Identification-个人
{%block content%}
{%if personne.Image%}
{%endif%}
@login_required
def Identity_Individu_PDF(request, id) :
folderId = None
personne = get_object_or_404(Individu, pk=id)
data = {"personne" :personne}
template = get_template('Identity_Individu_raw.html') # A modifier : template pdf généré
html = template.render(Context(data))
result = StringIO.StringIO()
NumeroIdentification = str(Individu.objects.get(pk=id).NumeroIdentification.encode('utf-8'))
NumeroIdentification_2 = NumeroIdentification.replace(" ", "")
filename_directory = str(Individu.objects.get(pk=id).Nom.encode('utf-8')) + "_" + str(Individu.objects.get(pk=id).Prenom.encode('utf-8')) + "_" + NumeroIdentification_2
filename_init = 'Fiche_Identification_' + filename_directory
filename = filename_init + '.pdf'
path = Global_variables.Individu_path.path + filename
file = open(path, "w+b")
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("utf-8")), file)
file.close()
<h2 align="center"> <font size="6"> Fiche d'Identification - INDIVIDU</font></align> </h2>
<br></br>
<br></br>
{% block content %}
{% if personne.Image %}
<img src='/Users/Desktop/Django/DatasystemsCORE/Photos_Identifications/pictures/19312STRASBOURG-614245.jpg' class="img-responsive"/>
{% endif %}