<标题><正文>和<页脚>xhtml2pdf | 标签无法正常工作姜戈页脚>正文>标题>
我正在使用 xhtml2pdf 将 html 页面渲染为 pdf,我希望有一个页眉和页脚,每个新页面都会重复。我尝试使用 html 的标签
和
知道哪个可能是问题吗?
我在分页中也遇到了问题:我已经在 stackoverflow 中查找过类似的问题,但我无法处理该问题。
我的 template.html 必须以 pdf 格式呈现。
<!DOCTYPE html>
<style type="text/css">
table{
padding-top: 10px;
border-right: 1.5px solid black;
border-left: 1.5px solid black;
}
.intestazione {
padding-top: 10px;
border-right: 0.5px solid black;
border-left: 0.5px solid black;
}
.vuota {
background-color: grey;
}
.vuota2{
border-top: 0px;
border-bottom: 0px;
border-left:0px;
border-right:0px;
}
td{
margin-left: 5px;
border: 0.5px solid black;
}
th{
border: 0.5px solid black;
}
.interno {
border-top: 0.3px solid black;
border-bottom: 0.3px solid black;
}
.center2 {
margin: auto;
width: 5%;
}
</style>
<html>
<header>
<div class="center2">
<table class="intestazione">
<tr>
<td rowspan="2" style="width:200px; height:200px; padding-top:-20px; padding-bottom: -20px; padding-left: 5px"><img src="image.png" size=100></td>
<td style="font-size: 10px; width: 450px;"><center><b>MODULE</b></center></td>
<td style="font-size: 10px; width:80px; height:30px"><center><b>MD74200AZ.003</b></center></td>
</tr>
<tr>
<td style="font-size: 13px; font-weight: bold; width: 450px;"><center>TITLE</center></td>
<td style="font-size: 10px;"><center>PAG. 1/6</center></td>
</tr>
</table>
</div>
</header>
<footer>BlaBla</footer>
<br>
<body>
<table style="border-top: 1.5px solid black">
<tr>
<td style="font-weight: bold;">STRUTTURA</td>
<td>{{att.Struttura}}</td>
<td style="font-weight: bold;">DATA</td>
<td>{{att.Data}}</td>
</tr>
</table>
<table>
<tr>
<!-- etc etc -->
</body>
我的views.py:
def export_pdf(request, pk):
att = MAIN.objects.get(id=pk)
specs = Specifiche.objects.filter(ID_rich=pk)
lista=[]
for spec in specs:
lista+=[spec.id]
uns = Unicita.objects.filter(rifext__in=lista)
crs = Criteri.objects.filter(ID_rich = pk)
cons = Consumabili.objects.filter(ID_rich = pk)
context = {'att': att, 'uns': uns, 'specs': specs, 'crs':crs, 'cons':cons}
template = get_template('modulorichiesta.html')
html = template.render(context)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1", "ignore")), result)
response = HttpResponse(result.getvalue(), content_type="application/pdf")
filename = str(att.Protocollo) + str(timezone.now())
content = "attachement; filename='%s'"%(filename)
response["Content-Disposition"] = content
return response
I'm using xhtml2pdf to render an html page to pdf and I would like to have a page header and a page footer which repeats for every new page. I've tried to use the tag <header>
and <footer>
of html but actually these don't work: they just show up in the page right in the position I wrote the code.
Any idea of which could be the problem?
I've also problems in the pagination: I've already looked in stackoverflow for similar questions but I couldn't handle the problem.
MY template.html that has to render in pdf.
<!DOCTYPE html>
<style type="text/css">
table{
padding-top: 10px;
border-right: 1.5px solid black;
border-left: 1.5px solid black;
}
.intestazione {
padding-top: 10px;
border-right: 0.5px solid black;
border-left: 0.5px solid black;
}
.vuota {
background-color: grey;
}
.vuota2{
border-top: 0px;
border-bottom: 0px;
border-left:0px;
border-right:0px;
}
td{
margin-left: 5px;
border: 0.5px solid black;
}
th{
border: 0.5px solid black;
}
.interno {
border-top: 0.3px solid black;
border-bottom: 0.3px solid black;
}
.center2 {
margin: auto;
width: 5%;
}
</style>
<html>
<header>
<div class="center2">
<table class="intestazione">
<tr>
<td rowspan="2" style="width:200px; height:200px; padding-top:-20px; padding-bottom: -20px; padding-left: 5px"><img src="image.png" size=100></td>
<td style="font-size: 10px; width: 450px;"><center><b>MODULE</b></center></td>
<td style="font-size: 10px; width:80px; height:30px"><center><b>MD74200AZ.003</b></center></td>
</tr>
<tr>
<td style="font-size: 13px; font-weight: bold; width: 450px;"><center>TITLE</center></td>
<td style="font-size: 10px;"><center>PAG. 1/6</center></td>
</tr>
</table>
</div>
</header>
<footer>BlaBla</footer>
<br>
<body>
<table style="border-top: 1.5px solid black">
<tr>
<td style="font-weight: bold;">STRUTTURA</td>
<td>{{att.Struttura}}</td>
<td style="font-weight: bold;">DATA</td>
<td>{{att.Data}}</td>
</tr>
</table>
<table>
<tr>
<!-- etc etc -->
</body>
My views.py:
def export_pdf(request, pk):
att = MAIN.objects.get(id=pk)
specs = Specifiche.objects.filter(ID_rich=pk)
lista=[]
for spec in specs:
lista+=[spec.id]
uns = Unicita.objects.filter(rifext__in=lista)
crs = Criteri.objects.filter(ID_rich = pk)
cons = Consumabili.objects.filter(ID_rich = pk)
context = {'att': att, 'uns': uns, 'specs': specs, 'crs':crs, 'cons':cons}
template = get_template('modulorichiesta.html')
html = template.render(context)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1", "ignore")), result)
response = HttpResponse(result.getvalue(), content_type="application/pdf")
filename = str(att.Protocollo) + str(timezone.now())
content = "attachement; filename='%s'"%(filename)
response["Content-Disposition"] = content
return response
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论