[reportlab-users] Subclassing BaseDocTemplate

Nicholas Wieland nicholas_wieland at yahoo.it
Mon Aug 22 04:54:32 EDT 2005


Hi *, I want to subclass BaseDocTemplate as suggested in this list, to use handle_pageBegin and similar methods.
 
 
 
class IReportDocTemplate (BaseDocTemplate):
 
  def __init__ (self, ptf_data, *args, **kwds):
    self._doc = BaseDocTemplate (
      filename = ptf_data ['ptf_code'] + '_' + str (ptf_data ['reference_date']).replace ('/', ''), 
      kwds)
    self.dossier_number = ptf_data ['dossier_number']
    self.reference_date = ptf_data ['reference_date']
 
  def handle_pageBegin (self):
    self._handle_pageBegin ()
    self._doc.canv.saveState ()
    logo = Image.open (_product_home + "/images/logompsam.gif")
    self._doc.canv.drawInlineImage (logo, 6, defaultPageSize [1] - 30, width = 100, height = 25)
    canvas.setFont('Tahoma', 12)
    canvas.drawCentredString (defaultPageSize [0] // 2, defaultPageSize [1] - 25,
      "Dossier n.: " + self.dossier_number)
    y, m, d = str (self.reference_date).split ("/")
    d = datetime.date (int (y), int (m), int (d))
    self._doc.canv.drawCentredString (defaultPageSize [0] - 60, defaultPageSize [1] - 25,
      d.strftime ("%B %d, %Y"))
    self._doc.canv.restoreState ()

  def build (self, flowables):
    self._calc ()
    self._doc.build (self, flowables)
 
 
 
Obviously this doesn't work. I looked at the SimpleDocTemplate, but it doesn't subclass __init__, that's why I'm having troubles.
Can someone post a simple example on how to subclass BaseDocTemplate ?
I can't use SimpleDocTemplate because I have a different PageTemplate for every page. Now I'm using the onPage and onPageEnd methods of PageTemplates, but I don't like it, as I have to use a global variable to display what I want.
I can of course use what John P. suggested in another post, but I'd like to subclass BaseDocTemplate directly, or at least try :)
 
TIA,
  ngw

		
---------------------------------
Yahoo! Mail: gratis 1GB per i messaggi, antispam, antivirus, POP3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://two.pairlist.net/pipermail/reportlab-users/attachments/20050822/e3fa5ea1/attachment.html


More information about the reportlab-users mailing list