Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:如何使Reportlab移到PDF输出中的下一行_Python_Pdf Generation_Reportlab - Fatal编程技术网

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

Python:如何使Reportlab移到PDF输出中的下一行,python,pdf-generation,reportlab,Python,Pdf Generation,Reportlab,我目前正在查询数据库中的数据,将其放入Python中的列表中,然后迭代这些列表,以便将数据打印到PDF中。我已经阅读了网站上的文件 问题:当当前行超出页面右边框时,我无法跳转到新行。我需要一个“回报” 以下是我现在拥有的: x = 72 #1 inch margin from y = 720 #10 inch margin from bottom mypdf = canvas.Canvas(response) #new canvas called 'mypdf' mypdf.setPageSiz

我目前正在查询数据库中的数据,将其放入Python中的列表中,然后迭代这些列表,以便将数据打印到PDF中。我已经阅读了网站上的文件

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

以下是我现在拥有的:

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个数据点,每个(当前)打印在一行上。

使用可流动的段落…可能重复感谢@JoranBeasley我在寻找一个类似的问题!
list1 = ['item 1.1 is a sentence that drags on and continues and talks about this or that or something else but at this point it is off the side of the page', 'item 1.2', 'item 1.3',]