我正在使用on page函数和页面模板为文档中的一个子集生成页眉:
templates.append(PageTemplate(id='Overview', frames=frame, onPage=HeaderOverview))
此模板的标题函数:
^{pr2}$这很好用,除了传递的course变量(它随节中的每个页面而变化)是序列中的最后一个变量,因为这个函数直到最终构建才真正被调用(我想这就是它的工作原理)。我需要的是这样做,这样值就是页面上的值。如果我能边写边画,那也没问题。下面是我的尝试:
####################################################################################
# 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"]))
这不会抛出错误或任何东西,但它似乎也不会实际绘制任何内容。在
谢谢你的帮助!在
还有一个主意。。。在
也许它可以使用特定的可识别的流程来更新课程。如果有必要,可以向流式添加自定义属性以帮助标识它们(请参见thispost)。在
例如,您可以执行以下操作:
并设置一些变量:
^{pr2}$然后,您可以在每个流呈现后检查它是否具有该属性,如果有,则更新当前进程。在
HeaderOverview
将能够使用current_course
变量来获得正确的方向,因为在最终构建过程中,HeaderOverview
和{相关问题 更多 >
编程相关推荐