reportlab 生成PDF如何將內(nèi)容左右顯示

1.背景

在reportlab中可以使用SimpleDocTemplate創(chuàng)建一個文檔,然后向里面添加內(nèi)容,但是直接添加內(nèi)容只能將值上下顯示,如果要將內(nèi)容左右顯示的話,可以使用reportlab中BalancedColumns,它可以將內(nèi)容分割成兩個或者更多大小相等的列。

2.使用

from reportlab.platypus.flowables import BalancedColumns
from reportlab.platypus.frames import ShowBoundaryValue
mytable = [[1,2,3,4],[5,6,7]]#按照這個格式填寫
img_activity=Image('./image/**.png')
F = [ mytable, img_activity]#在該列表中填寫需要分列展示的內(nèi)容
story.append(
 Balanced(
 F, #the flowables we are balancing
 nCols = 2, #the number of columns
 needed = 72,#the minimum space needed by the flowable
 spacBefore = 0,
 spaceAfter = 0,
 showBoundary = None, #optional boundary showing
leftPadding=None, #these override the created frame
 rightPadding=None, #paddings if specified else the
 topPadding=None, #default frame paddings
 bottomPadding=None, #are used
 innerPadding=None, #the gap between frames if specified else
 #use max(leftPadding,rightPadding)
 name='', #for identification purposes when stuff goes awry
 endSlack=0.1, #height disparity allowance ie 10% of available height
 )
 )

分列顯示的內(nèi)容,可以是表格、圖表、文字等
只是這樣將內(nèi)容分列,內(nèi)容上面的顯示仍然不是特別的靈活。

3.效果展示

image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容