如何解决Reportlab:修复标头,使其不能向上移动?
我正在尝试使用python和ReportLab创建发票生成器,我使用画布制作我的pdf文件(table.wrapOn和table.drawOn方法)。现在,当我添加一个项目时,表格的标题会向上。我希望标题是固定的,并且每次添加项目时,表格都会往下移。
import json
from reportlab.pdfgen import canvas
with open('json/data.json') as json_file:
products = json.load(json_file)
eindtotaal = 0
data = [
['Aantal','Productnaam','BTW','Prijs','Totaal (incl. BTW)']
]
for item in products:
aantal = item['Aantal']
omschrijving = item['Omschrijving']
prijs = item['Prijs']
totaal = '{:.2f}'.format(aantal*prijs)
eindtotaal += aantal*prijs
lijst = [aantal,omschrijving,item['BTW'],prijs,totaal]
data.append(lijst)
data.append(['','',eindtotaal])
fileName = 'invoice.pdf'
from reportlab.platypus import SimpleDocTemplate
from reportlab.lib.pagesizes import A4
pdf = canvas.Canvas(fileName)
from reportlab.platypus import Table
table = Table(data)
from reportlab.platypus import TableStyle
from reportlab.lib import colors
style = TableStyle([
('TEXTCOLOR',(0,0),(-1,-1),colors.black),('ALIGN','CENTER'),(4,'RIGHT'),(1,'LEFT'),('FONTNAME','Courier-Bold'),('FONTSIZE',12),14),('BOTTOMPADDING',1),9),('TOPPADDING',9)
])
table.setStyle(style)
ts = TableStyle(
[
('LINEBELOW',2,('LINEBELOW',-2),0.5,colors.grey)
]
)
table.setStyle(ts)
table.wrapOn(pdf,0)
table.drawOn(pdf,100,500)
pdf.showPage()
pdf.save()
我的json数据:
[
{
"Prijs": 249.99,"Aantal": 5,"Omschrijving": "Article 1","BTW": "21%"
},{
"Prijs": 21.95,"Aantal": 2,"Omschrijving": "Article 2","BTW": "21%"
}
]
现在,当我向json数组中添加项目时,表格的标题就会上升。
对不起,荷兰语。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。