reportlab 设置左表位置

标签 reportlab

如何设置表格的左侧位置?

response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=%s' % pdf_name
buffer = StringIO()
PAGESIZE = pagesizes.portrait(pagesizes.A4)
doc = SimpleDocTemplate(buffer, pagesize=PAGESIZE, leftMargin=1*cm)
story = []

story.append(Paragraph(header_part2, styleN))
table_row = ['Total Score:','']
data.append(table_row)
ts = [
    #header style    
    ('LINEABOVE', (0,0), (-1,0), 1, colors.gray),
    ('LINEBELOW', (0,0), (-1,0), 1, colors.gray)]
t = Table(data, (6*cm,6*cm), None, style=ts)
    story.append(t)
    doc.build(story)
    pdf = buffer.getvalue()
buffer.close()
response.write(pdf)

段落打印时距左侧一厘米,而表格打印时与左页面边框几乎没有距离。

我必须在哪里设置表格位置的 leftMargin?

这同样适用于我添加的图像。它们似乎印在某处。
story.append(Image(path,35,10))

最佳答案

找到了神奇的 hAlign 关键字:

t = Table(data, (6*cm,6*cm,2*cm,2*cm,2*cm), None, style=ts, hAlign='LEFT')

关于reportlab 设置左表位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11818985/

相关文章:

python - Reportlab 中的 Pandas DataFrames

python - 如何在 python reportlab pdf 生成中使用十六进制颜色值

python - 在 ReportLab 中向 Canvas 元素添加超链接的最简单方法是什么?

python - 图表数据,网站浏览量用什么平台

python - Lulu 希望在我的 reportlab PDF 中嵌入字体以出版一本书

arabic - 在 ReportLab 中使用阿拉伯语 (RTL)

python - 无法使用 subprocess.Popen 在 Web 服务中打开 pdf 文件

python - 为什么我在生成 pdf 时在 reportlab 中收到 "memory error"

python - Reportlab 中的段落 overflow hidden

python - 使用 Flask - Python 下载 ReportLab PDF