Overwrote a ReportLab BaseDocTemplate class and it works but im not sure why

Viewed 11

I overwrote the BaseDocTemplate class so that on the start of every page I can insert a flowable to the head of the flowable list so that a desired flowable will be at the beginning of every page.

This works but i cannot figure out why. Would someone be able to explain what i am missing?


    def __init__(self, filename, **kw):
        self._remaining_flowables = None
        super().__init__(filename, leftMargin = 0, rightMargin=0, topMargin=0, bottomMargin=0, pagesize=LETTER)

    def build(self, flowables):
        if not self._remaining_flowables:
            self._remaining_flowables = flowables
        
        if len(self._remaining_flowables) > len(flowables):
            flowables = self._remaining_flowables
        else:
            self._remaining_flowables = flowables

        return super().build(flowables)

    def beforePage(self):
        self._remaining_flowables.insert(0, Paragraph("BEGIN"))
        print(self._remaining_flowables)
        return super().beforePage()
'''
0 Answers
Related