我在页面上使用功能和页面模板,使头对我的文档页面的一个子集:ReportLab的:数据头信息
templates.append(PageTemplate(id='Overview', frames=frame, onPage=HeaderOverview))
此模板的头功能:
################################
# Function HeaderOverview - header for overview page
def HeaderOverview(canvas,doc):
canvas.saveState()
headboxh = 15
headboxx = 20
headboxy = 730
headboxw = 570
canvas.rect(headboxx, headboxy, headboxw, headboxh, fill=1)
canvas.setFillColor(colors.black)
canvas.setFont("Helvetica", 14)
canvas.setFillColor(colors.white)
canvas.drawString(headboxx + 15,headboxy+.25*headboxh,"Mathematics")
textWidth = stringWidth("Mathematics", "Helvetica", 12)
canvas.setFont("Helvetica", 12)
canvas.drawString(headboxw - 15 - textWidth,headboxy+.25*headboxh,course)
canvas.restoreState()
这个伟大的工程,但则传递过程变量(每个页面的部分改变)是序列中的最后一个,因为这个功能不是真的叫,直到最终版本(我认为这是如何有用)。我需要的是做到这一点,使价值是在网页上的价值。如果我可以在我写页面的时候绘制它,那也可以。这是我尝试在那:
####################################################################################
# Function makeGradeOverview(course): makes Overview chart for grade
#
def makeGradeOverview(canvas, course):
report.append(NextPageTemplate("Overview"))
report.append(PageBreak())
headboxh = 50
headboxx = 20
headboxy = 600#730
headboxw = 540
canvas.saveState()
canvas.setFont("Helvetica", 12)
textWidth = stringWidth(course, "Helvetica", 12)
canvas.drawString(headboxw - 15 - textWidth,headboxy+.25*headboxh,course)
canvas.restoreState()
# put course name as title
if len(course)<=2:
headerrow = ''.join(['Grade ', course, ' Overview'])
else:
headerrow = ''.join([course, ' Overview'])
report.append(Paragraph(headerrow, styles["Overview Title"]))
report.append(Spacer(1, 16))
GridInfo = []
topics = topiclist(course)
for topic in topics:
report.append(Paragraph(topic, styles["Overview Sub"]))
report.append(Spacer(1, 8))
subtopics = subtopiclist(course, topic)
sublist = []
for subtopic in subtopics:
report.append(Paragraph(''.join([r'<bullet>&bull</bullet>',subtopic]), styles["Overview Table"]))
这不会引发错误或任何东西,但它似乎并不实际绘制任何东西,无论是。
感谢您的帮助!
afterPage或afterDrawPage可能会涉及,但我不知道如何构建这些来使用当前页面的信息 – DeltaG 2013-02-17 12:46:06
您可以提供更多关于第一次尝试的'course'变量的上下文。它如何/在哪里设置/更改?你有一个包含'HeaderOverview'需要使用的课程的列表吗? – grc 2013-03-01 12:44:33
我正在循环设置课程列表,每次我编写新课程的页面时都会调用此函数。在循环遍历整个列表之后,我有一组页面,并且课程变量会更改每个页面或每个其他页面,以反映页面上的信息。 – DeltaG 2013-03-01 16:38:49