def __init__( self, container, x1, y1, width, height, leftPadding=6, bottomPadding=6, rightPadding=6, topPadding=6, id=None, showBoundary=0, overlapAttachedSpace=None, _debug=None, ): self.container = container self.onSidebar = False self.__s = '[%s, %s, %s, %s, %s, %s, %s, %s,]' % ( x1, y1, width, height, leftPadding, bottomPadding, rightPadding, topPadding, ) Frame.__init__( self, x1, y1, width, height, leftPadding, bottomPadding, rightPadding, topPadding, id, showBoundary, overlapAttachedSpace, _debug, )
class MySimpleDocTemplate(BaseDocTemplate): """ The document template used for all PDF documents. """ def __init__(self, filename, context, **kw): BaseDocTemplate.__init__(self, filename, **kw) self.toc_index = 0 self.main_frame_attr = { 'x1': self.leftMargin, 'y1': self.bottomMargin, 'width': self.width, 'height': self.height, 'id': 'normal', 'showBoundary': self.showBoundary } # We keep the main frame reference to resize it during the build self.main_frame = Frame(**self.main_frame_attr) self.main_frame_change = False template_attrs = { 'id': 'now', 'frames': [self.main_frame], 'pagesize': kw['pagesize'] } page_template = PageTemplate(**template_attrs) self.platypus_header_calculate = False self.platypus_header_height = None self.platypus_footer = None self.context = context self.addPageTemplates([page_template]) self.toc_high_level = self.context.toc_high_level self.frame_attr = { 'leftPadding': 0, 'bottomPadding': 6, 'rightPadding': 0, 'topPadding': 6, 'showBoundary': 0 } self.context = context # calculate width available self.width_available = self.width self.width_available -= self.frame_attr['leftPadding'] self.width_available -= self.frame_attr['rightPadding'] def beforePage(self): self.context.current_page += 1 if self.context.has_header(): # HEADER header = self.context.get_header() self.canv.saveState() # calculate height if self.platypus_header_calculate is False: element = header[0] height = element.wrap(self.width_available, self.pagesize[1])[1] height += self.frame_attr['topPadding'] height += self.frame_attr['bottomPadding'] self.platypus_header_height = height height = self.platypus_header_height # calculate coordinates x = self.leftMargin y = self.pagesize[1] - height # resize margin if the frame is too big if self.platypus_header_calculate is False: if self.topMargin < height: self.platypus_header_calculate = True self.topMargin = height # calculate self.width and self.height self._calc() # reset the main frame with new margin self.main_frame_attr['x1'] = self.leftMargin self.main_frame_attr['y1'] = self.bottomMargin self.main_frame_attr['width'] = self.width self.main_frame_attr['height'] = self.height self.main_frame.__init__(**self.main_frame_attr) else: # frame is centered in top margin y -= (self.topMargin - height) / 2 else: # frame is centered in top margin y -= (self.topMargin - height) / 2 # create a frame which will contain all platypus objects defined # in the footer fh = Frame(x, y, self.width_available, height, **self.frame_attr) fh.addFromList(self.context.get_header_copy(), self.canv) self.canv.restoreState() if self.context.has_footer(): # FOOTER footer = self.context.get_footer() self.canv.saveState() # calculate height element = footer[0] height = element.wrap(self.width_available, self.pagesize[1])[1] height += self.frame_attr['topPadding'] height += self.frame_attr['bottomPadding'] # calculate coordinates x = self.leftMargin y = 0 # resize margin if the frame is too big if self.bottomMargin < height: self.bottomMargin = height # calculate self.width and self.height self._calc() # reset the main frame with new margin self.main_frame_attr['x1'] = self.leftMargin self.main_frame_attr['y1'] = self.bottomMargin self.main_frame_attr['width'] = self.width self.main_frame_attr['height'] = self.height self.main_frame.__init__(**self.main_frame_attr) else: # frame is centered in bottom margin y = (self.bottomMargin - height) / 2 # create a frame which will contain all platypus objects defined # in the footer ff = Frame(x, y, self.width_available, height, **self.frame_attr) ff.addFromList(self.context.get_footer_copy(), self.canv) self.canv.restoreState()
class MySimpleDocTemplate(BaseDocTemplate): """ The document template used for all PDF documents. """ def __init__(self, filename, context, **kw): BaseDocTemplate.__init__(self, filename, **kw) self.toc_index = 0 self.main_frame_attr = {'x1': self.leftMargin, 'y1': self.bottomMargin, 'width': self.width, 'height': self.height, 'id':'normal', 'showBoundary': self.showBoundary} # We keep the main frame reference to resize it during the build self.main_frame = Frame(**self.main_frame_attr) self.main_frame_change = False template_attrs = {'id': 'now', 'frames': [self.main_frame], 'pagesize': kw['pagesize']} page_template = PageTemplate(**template_attrs) self.platypus_header_calculate = False self.platypus_header_height = None self.platypus_footer = None self.context = context self.addPageTemplates([page_template]) self.toc_high_level = self.context.toc_high_level self.frame_attr = {'leftPadding': 0, 'bottomPadding': 6, 'rightPadding': 0, 'topPadding': 6, 'showBoundary': 0} self.context = context # calculate width available self.width_available = self.width self.width_available -= self.frame_attr['leftPadding'] self.width_available -= self.frame_attr['rightPadding'] def beforePage(self): self.context.current_page += 1 if self.context.has_header(): # HEADER header = self.context.get_header() self.canv.saveState() # calculate height if self.platypus_header_calculate is False: element = header[0] height = element.wrap(self.width_available, self.pagesize[1])[1] height += self.frame_attr['topPadding'] height += self.frame_attr['bottomPadding'] self.platypus_header_height = height height = self.platypus_header_height # calculate coordinates x = self.leftMargin y = self.pagesize[1] - height # resize margin if the frame is too big if self.platypus_header_calculate is False: if self.topMargin < height: self.platypus_header_calculate = True self.topMargin = height # calculate self.width and self.height self._calc() # reset the main frame with new margin self.main_frame_attr['x1'] = self.leftMargin self.main_frame_attr['y1'] = self.bottomMargin self.main_frame_attr['width'] = self.width self.main_frame_attr['height'] = self.height self.main_frame.__init__(**self.main_frame_attr) else: # frame is centered in top margin y -= (self.topMargin - height) / 2 else: # frame is centered in top margin y -= (self.topMargin - height) / 2 # create a frame which will contain all platypus objects defined # in the footer fh = Frame(x, y, self.width_available, height, **self.frame_attr) fh.addFromList(self.context.get_header_copy(), self.canv) self.canv.restoreState() if self.context.has_footer(): # FOOTER footer = self.context.get_footer() self.canv.saveState() # calculate height element = footer[0] height = element.wrap(self.width_available, self.pagesize[1])[1] height += self.frame_attr['topPadding'] height += self.frame_attr['bottomPadding'] # calculate coordinates x = self.leftMargin y = 0 # resize margin if the frame is too big if self.bottomMargin < height: self.bottomMargin = height # calculate self.width and self.height self._calc() # reset the main frame with new margin self.main_frame_attr['x1'] = self.leftMargin self.main_frame_attr['y1'] = self.bottomMargin self.main_frame_attr['width'] = self.width self.main_frame_attr['height'] = self.height self.main_frame.__init__(**self.main_frame_attr) else: # frame is centered in bottom margin y = (self.bottomMargin - height) / 2 # create a frame which will contain all platypus objects defined # in the footer ff = Frame(x, y, self.width_available, height, **self.frame_attr) ff.addFromList(self.context.get_footer_copy(), self.canv) self.canv.restoreState()