src/reportlab/platypus/doctemplate.py
changeset 4212 c903815560d1
parent 4211 464df39467fc
child 4228 fd5bbccc7758
equal deleted inserted replaced
4211:464df39467fc 4212:c903815560d1
   249     essentially a list of Frames and an onPage routine to call at the start
   249     essentially a list of Frames and an onPage routine to call at the start
   250     of a page when this is selected. onPageEnd gets called at the end.
   250     of a page when this is selected. onPageEnd gets called at the end.
   251     derived classes can also implement beforeDrawPage and afterDrawPage if they want
   251     derived classes can also implement beforeDrawPage and afterDrawPage if they want
   252     """
   252     """
   253     def __init__(self,id=None,frames=[],onPage=_doNothing, onPageEnd=_doNothing,
   253     def __init__(self,id=None,frames=[],onPage=_doNothing, onPageEnd=_doNothing,
   254                  pagesize=None, autoNextPageTemplate=None):
   254                  pagesize=None, autoNextPageTemplate=None,
       
   255                  cropBox=None,
       
   256                  artBox=None,
       
   257                  trimBox=None,
       
   258                  bleedBox=None,
       
   259                  ):
   255         frames = frames or []
   260         frames = frames or []
   256         if not isSeq(frames): frames = [frames]
   261         if not isSeq(frames): frames = [frames]
   257         assert [x for x in frames if not isinstance(x,Frame)]==[], "frames argument error"
   262         assert [x for x in frames if not isinstance(x,Frame)]==[], "frames argument error"
   258         self.id = id
   263         self.id = id
   259         self.frames = frames
   264         self.frames = frames
   260         self.onPage = onPage
   265         self.onPage = onPage
   261         self.onPageEnd = onPageEnd
   266         self.onPageEnd = onPageEnd
   262         self.pagesize = pagesize
   267         self.pagesize = pagesize
   263         self.autoNextPageTemplate = autoNextPageTemplate
   268         self.autoNextPageTemplate = autoNextPageTemplate
       
   269         self.cropBox = cropBox
       
   270         self.artBox = artBox
       
   271         self.trimBox = trimBox
       
   272         self.bleedBox = bleedBox
   264 
   273 
   265     def beforeDrawPage(self,canv,doc):
   274     def beforeDrawPage(self,canv,doc):
   266         """Override this if you want additional functionality or prefer
   275         """Override this if you want additional functionality or prefer
   267         a class based page routine.  Called before any flowables for
   276         a class based page routine.  Called before any flowables for
   268         this page are processed."""
   277         this page are processed."""
   286         if cp!=sp:
   295         if cp!=sp:
   287             if sp:
   296             if sp:
   288                 canv.setPageSize(self.pagesize)
   297                 canv.setPageSize(self.pagesize)
   289             elif cp!=dp:
   298             elif cp!=dp:
   290                 canv.setPageSize(doc.pagesize)
   299                 canv.setPageSize(doc.pagesize)
       
   300         for box in 'crop','art','trim','bleed':
       
   301             size = getattr(self,box+'Box',None)
       
   302             if size:
       
   303                 canv.setCropBox(size,name=box)
   291 
   304 
   292     def afterDrawPage(self, canv, doc):
   305     def afterDrawPage(self, canv, doc):
   293         """This is called after the last flowable for the page has
   306         """This is called after the last flowable for the page has
   294         been processed.  You might use this if the page header or
   307         been processed.  You might use this if the page header or
   295         footer needed knowledge of what flowables were drawn on
   308         footer needed knowledge of what flowables were drawn on
   454                     'displayDocTitle': None,
   467                     'displayDocTitle': None,
   455                     'lang': None,
   468                     'lang': None,
   456                     'initialFontName': None,
   469                     'initialFontName': None,
   457                     'initialFontSize': None,
   470                     'initialFontSize': None,
   458                     'initialLeading': None,
   471                     'initialLeading': None,
       
   472                     'cropBox': None,
       
   473                     'artBox': None,
       
   474                     'trimBox': None,
       
   475                     'bleedBox': None,
   459                     }
   476                     }
   460     _invalidInitArgs = ()
   477     _invalidInitArgs = ()
   461     _firstPageTemplateIndex = 0
   478     _firstPageTemplateIndex = 0
   462 
   479 
   463     def __init__(self, filename, **kw):
   480     def __init__(self, filename, **kw):
   861                                 pageCompression=self.pageCompression,
   878                                 pageCompression=self.pageCompression,
   862                                 enforceColorSpace=self.enforceColorSpace,
   879                                 enforceColorSpace=self.enforceColorSpace,
   863                                 initialFontName = self.initialFontName,
   880                                 initialFontName = self.initialFontName,
   864                                 initialFontSize = self.initialFontSize,
   881                                 initialFontSize = self.initialFontSize,
   865                                 initialLeading = self.initialLeading,
   882                                 initialLeading = self.initialLeading,
       
   883                                 cropBox = self.cropBox,
       
   884                                 artBox = self.artBox,
       
   885                                 trimBox = self.trimBox,
       
   886                                 bleedBox = self.bleedBox,
   866                                 )
   887                                 )
   867 
   888 
   868         getattr(self.canv,'setEncrypt',lambda x: None)(self.encrypt)
   889         getattr(self.canv,'setEncrypt',lambda x: None)(self.encrypt)
   869 
   890 
   870         self.canv._cropMarks = self.cropMarks
   891         self.canv._cropMarks = self.cropMarks