如何在没有 SimpleDocTemplate 的情况下使用 reportlab 添加表格

问题描述

@H_502_0@我正在尝试使用 reportLab 从 python 创建发票并将其制作为 PDF 文档。 我已添加收据的主要内容,例如徽标、姓名地址等信息...

@H_502_0@我当前的 PDF 看起来像这样...

pdf image

@H_502_0@到目前为止我的代码是这样的......

from reportlab.platypus import Table,TableStyle
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib.pagesizes import letter
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfgen import canvas
from reportlab.lib import colors


pdfmetrics.registerFont(TTFont('font1','RobotoSlab-VariableFont_wght.ttf'))
pdfmetrics.registerFont(TTFont('font2','Montserrat-ExtraBold.ttf'))


pdf = canvas.Canvas('purchaseReciept.pdf')
pdf.setTitle('eblossom.lk')

# 1) Title and logo
pdf.setFont('font2',42)
pdf.drawCentredString(130,750,"RECIEPT")

pdf.drawImage('logo.png',440,570,width=130,height=None,mask=None,preserveAspectRatio=True,anchor='c')


# 2) Add eblossom office address
text = pdf.beginText(40,725)
text.setFont('Courier',10)
text.textLine('No 83/15,Station Road')
text.textLine('Angulana,Moratuwa')
text.textLine('Tel: +94 77 394 2550')
text.textLine('Email: [email protected]')

pdf.drawText(text)

# 3) Add the user's address details

text = pdf.beginText(40,650)
text.setFont('font2',12)
text.setFillColor(colors.hotpink)
text.textLine("DELIVER TO")
text.setFont('font1',9)
text.setFillColor(colors.black)
text.textLine('No 10A blah,Colombo 06')
text.textLine('Wellewatte,Sri Lanka')
text.textLine('00600')
text.textLine('The road near NDB bank')

pdf.drawText(text)

# 4) Add the order Number
pdf.setFont('font2',12)
pdf.setFillColor(colors.hotpink)
pdf.drawCentredString(500,650,'Order No #332')


pdf.save()
@H_502_0@不过,现在我想知道的是如何添加一个表。我知道如何使用 SimpledocTemplate 添加表格,但我想知道如何在不更改代码的当前结构的情况下添加表格。

@H_502_0@任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)