使用“TopPadder”尝试这个可行的示例(结果是总数被推到框架的底部,我假设您可以在下面添加一个缓冲垫,以控制从底部开始的高度):
########################################################################
from reportlab.lib.units import mm
from reportlab.platypus import Paragraph, Spacer, Table, TableStyle
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import SimpleDocTemplate
from reportlab.platypus.flowables import TopPadder
import io
def create_pdf():
styles=getSampleStyleSheet()
# add invoice header
flowable_list = [
Spacer(1, 5 * mm),
Paragraph(f'Date: ...', styles['Normal']),
Spacer(1, 5 * mm),
]
# add invoice details
detail_list = [
('Item 1', 8, 45),
('Item 2', 1, 14),
]
row_list = [
[
Paragraph(f'desc', styles['Normal']),
# quantity,
# amount,
]
for desc, quantity, amount in detail_list]
story = []
story.append(
Table(
data=row_list,
colWidths=[100 * mm, 40 * mm, 40 * mm],
style=TableStyle([
('VALIGN', (0, 0), (-1, -1), 'TOP'),
# ... some other options...
])))
# add invoice footer; this should be at a specific position on the page
flowable_list.append(Spacer(1, 5 * mm))
flowable_list.append(TopPadder(Paragraph(f'Total: 0', styles['Normal'])))
# build PDF
buffer = io.BytesIO()
doc = SimpleDocTemplate("test2.pdf")
doc.build(flowable_list)
# ----------------------------------------------------------------------
if __name__ == "__main__":
create_pdf() # Printing the pdf