Reportlab: header with data from page

蹲街弑〆低调 提交于 2019-12-01 18:50:05
grc

Here's another idea...

Perhaps it would work to use specific flowables that can be identified to update the course. You can add custom attributes to flowables if necessary to help identify them (see this post).

For example, you might be able to do something like this:

...
report.append(some_content)

report.append(PageBreak())
report[-1].new_course = True  # gives that PageBreak flowable a custom attribute

report.append(some_more_content)
...

And set up some variables:

course_list = [...]
course_iter = iter(course_list)
current_course = next(course_iter)

Then you can check each flowable after it is rendered to see if it has that attribute and update the current course if it does.

def afterFlowable(flowable):
    global current_course
    if hasattr(flowable, 'new_course'):
        current_course = next(course_iter)

doc.afterFlowable = afterFlowable

HeaderOverview will be able to use the current_course variable to get the right course, since both HeaderOverview and afterFlowable are called at various points during the final build.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!