Python:如何使Reportlab移动到PDF输出的下一行

时间:2018-06-01 20:39:51

标签: python pdf-generation reportlab

我目前正在查询来自数据库的数据,将其拉入Python中的列表,然后迭代这些列表以将该数据打印到PDF中。我已阅读了ReportLab's PDFGen Documentation的文档。

问题:当当前行超出页面的右边框时,我无法跳转到新行。我需要一个"返回。"

这就是我现在所拥有的:

<?php

现在,这遍历了我的两个列表。当内容位于1英寸底部边距内时,我会转到新页面。几乎所有列表项都适合页面。但是,如果我将列表项更改为超长,例如:

x = 72 #1 inch margin from
y = 720 #10 inch margin from bottom
mypdf = canvas.Canvas(response) #new canvas called 'mypdf'
mypdf.setPageSize(letter) #set size to 8.5x11
list1 = ['item 1.1', 'item 1.2', 'item 1.3',]
list2 = ['item 2.1', 'item 2.2', 'item 2.3',]

detaillist = [ list1, list2 ]

for details in detaillist:
    for line_item in details:
        mypdf.roundRect(x-15, y, 10, 10, 2, stroke=1) #each line item has a check box
        mypdf.drawString(x, y, line_item) #write the value for each line item at x,y coordinate
        y -= 14 #x, y coordinate goes down by 14/72s of an inch
        #if the current location is within bottom 1 inch margin
        if y < 72:
            y = 720 #reset y value
            page = canvas.Canvas(response) #create a new page
            mypdf.showPage() #show the new page
    mypdf.line(x,y,x*7.5,y) #draw a line to separate sections
    y -= 17 #add a buffer below the line

mypdf.save()

然后我的文字在页面的右侧运行。

我该怎么办? 我很高兴听到你如何处理这个问题。我有一个未知数量的列表要迭代,每个列表有10-20个数据点,每个(当前)打印在一行上。

0 个答案:

没有答案
相关问题