问题描述
大家好,我在reportlab样式方面不太擅长,我想用reportlab样式化表,我想要实现该图像中的样式,我想要连续2列,在第一列,我想要另外2列图像,细节和第二列中的内容,我想要相同的内容,如何在代码中尝试实现,但是我从未实现图像和细节之间的联系,而且我也遇到了一些错误,有人可以帮我吗
非常感谢
from reportlab.lib.pagesizes import letter,A4
from reportlab.platypus import SimpleDocTemplate,Table,TableStyle,Image
from reportlab.lib import colors
from reportlab.lib.units import inch
def get_pdf():
category = [
{
"id": 1,"name": "Fashion","img": "images/shirt.png","desciption": "This is descriptions"
},{
"id": 2,"name": "Electronic",{
"id": 3,"name": "Furniture",{
"id": 4,"name": "Automobile",]
filename = 'invoice.pdf'
PDF_title = 'My Company Name'
document_title = 'Category Invoice'
elements = []
category_table = []
pdf = SimpleDocTemplate(
filename,pagesize=A4,rightMargin=30,leftMargin=30,topMargin=30,bottomMargin=18
)
header_table = [['Category List']]
header_table_style = TableStyle([
('BOTTOMPADDING',(0,0),(-1,-1),30),('FONTSIZE',20),('ALIGN','CENTER'),])
header_table = Table(header_table,style=header_table_style)
category_table.append(
['Image','Details']
)
for i in range(len(category)):
img = Image(category[i]['img'],1*inch,1*inch)
category_table.append(
[img,[[category[i]['id']],[category[i]['name']],[category[i]['desciption']]]]
)
category_table_style = TableStyle([
('BOTTOMPADDING',15),16),('BOTTOMPADDING',1),(2,('TOPPADDING',3),(1,12),('RIGHTPADDING',70),])
category_table = Table(category_table,style=category_table_style)
elements.append(header_table)
elements.append(category_table)
pdf.build(elements)
print('PDF Created')
get_pdf()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)