Python ReportLab中的编号列表
我想使用reportlab打印缩进的编号列表 我想打印什么 欢迎来到我的名单Python ReportLab中的编号列表,python,reportlab,Python,Reportlab,我想使用reportlab打印缩进的编号列表 我想打印什么 欢迎来到我的名单 列表项 列表项 列表项 谢谢你的阅读 我的reportlab模板: from reportlab.pdfgen import canvas canvas = canvas.Canvas("mypdf.pdf", pagesize=letter) canvas.drawString(inch, inch, "Hello") canvas.save() 我无法从reportlab用户指南中获得用于画布的示例。如何将此列表
from reportlab.pdfgen import canvas
canvas = canvas.Canvas("mypdf.pdf", pagesize=letter)
canvas.drawString(inch, inch, "Hello")
canvas.save()
我无法从reportlab用户指南中获得用于画布的示例。如何将此列表打印到我的pdf中?将以下导入添加到脚本开头可以解决您收到的错误:
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
此外,如下所示设置bottomup参数将在页面的右上角开始文本
canvas = canvas.Canvas("mypdf.pdf", pagesize=letter, bottomup=0)
以下示例应按照您的描述创建PDF:
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
canvas = canvas.Canvas("mypdf.pdf", pagesize=letter, bottomup=0)
items = [
"List item one",
"List item two",
"List item three",
]
text_object = canvas.beginText(inch, inch)
text_object.textLine("Welcome to my list")
for index, item in enumerate(items):
text_object.textLine(" {}. {}".format(index + 1, item))
text_object.textLine("Thanks or reading")
canvas.drawText(text_object)
canvas.save()