reportlab canvas.showPage在循环条件下不起作用

时间:2017-06-26 10:49:14

标签: python python-2.7 canvas pdf-generation reportlab

我正在使用python reportlab生成pdf,在我的程序中我正在使用while循环生成多个pdf,如果用户想要继续但不是生成多个pdf而是需要它在包含多个页面的单个pdf中。

我的代码:

enter code here:
while put != "no":
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.pagesizes import landscape
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab import rl_config
from reportlab.lib import utils

pdfmetrics.registerFont(TTFont('Bookman Old Style', 'BOOKOSB.ttf'))

canvas = canvas.Canvas("saved.pdf" , pagesize=landscape(letter))
canvas.line(31.83,133,765.92,133) #"""bottom most line"""
canvas.line(31.83,133,31.83,419) #"""left most line"""
canvas.line(31.83,419,765.92,419) #"""top most line"""
canvas.line(765.92,133,765.92,419) #"""right most line"""
canvas.line(80.23,133,80.23,419) #"""1st column line"""
canvas.line(179.59,133,179.59,419) #"""2nd column line"""
canvas.line(226.39,133,226.39,419) #"""3rd column line"""
canvas.line(324.29,133,324.29,419) #""" 4th column line"""
canvas.line(371.09,133,371.09,419) #""" 5th column line"""
canvas.line(473.29,133,473.29,419) #""" 6th column line"""
canvas.line(520.09,133,520.09,419) #""" 7th column line"""
canvas.line(621.67,133,621.67,419) #""" 8th column line"""
canvas.line(667.03,133,667.03,419) #""" 9th column line"""

canvas.line(31.83,378.75,765.92,378.75)#"""1st row line"""
canvas.line(31.83,329.43,765.92,329.43)#"""2nd row line"""
canvas.line(31.83,280.11,765.92,280.11)#"""3rd row line"""
canvas.line(31.83,230.50,765.92,230.50)#"""4th row line"""
canvas.line(31.83,180.89,765.92,180.89)#"""5th row line"""
canvas.save()
put = raw_input("\ndo want to continue [yes] or [ no]: ")
if put == "yes":
    canvas.showPage()
else:

    print "Have a Nice Day"
    break

1 个答案:

答案 0 :(得分:0)

是的,我自己得到了答案,这是link供你参考。