[reportlab-users] Newbie - Basic BaseDocTemplate

Riaan Bekker riaan.bekker at kapabiosystems.com
Fri Jan 26 01:00:35 EST 2007


I can not get my BaseDocTemplate example to work.



If I move the BaseDocTemplate.__init__(self,name) after my variable
declaration, it never gets executed, if I move it before my variable
declaration, it never executes my variable declares. I am newbie to this, so
still struggling with it.



I also did not get the self.canv variable before, but I hope with this kind
of sub-classing that I can get hold of it and creaty my frames. Am I on the
right track here ? I just want to do a page with 3 columns and the top and a
detail section below that 2 columns, that is why I used 3 frames at the top,
and 1 frame for the body. The body will contain some kind of grid to display
row data, the top 3 frames will display data from static tables, but still
needs to be populated from the database. Where will be the best to populate
the tables and grid? I am connecting to a postgre-sql DB and also to
Microsoft GP.





from reportlab.pdfgen import canvas



from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle

from reportlab.lib import colors

from reportlab.lib.units import cm

from reportlab.lib.pagesizes import A4



from reportlab.platypus.tables import TableStyle, Table

from reportlab.platypus import BaseDocTemplate, Frame, Paragraph,
PageTemplate, Spacer



import datetime

import time

import wx

import os





class coaDocTemplate(BaseDocTemplate):



def __init__(self, name):



self.PAGE_WIDTH = A4[0]

self.PAGE_HEIGHT = A4[1]

self.CENTRE_WIDTH = self.PAGE_WIDTH/2.0

self.CENTRE_HEIGHT = self.PAGE_HEIGHT/2.0



self._frameLeft = Frame(self.PAGE_HEIGHT - 120, 30, (self.PAGE_WIDTH
/ 3),200)

self._frameMiddle = Frame(self.PAGE_HEIGHT - 120, (self.PAGE_WIDTH /
3), (self.PAGE_WIDTH / 3),200)

self._frameRight = Frame(self.PAGE_HEIGHT - 120, ((self.PAGE_WIDTH /
3) * 2), (self.PAGE_WIDTH / 3),200)



# frame for detail

self._frameBody = Frame(self.PAGE_HEIGHT - 320, self.PAGE_WIDTH,
self.PAGE_WIDTH, self.PAGE_HEIGHT - 400)



BaseDocTemplate.__init__(self,name)

self.fileName = name



def afterInit(self):



self.showBoundary = 1



# page layout

pageLayout = PageTemplate(id='Heading',frames=[self._frameLeft,
self._frameMiddle, self._frameRight, self._frameBody])

self.addPageTemplates([pageLayout])



def beforePage(self):



# create company logo

self.canv.drawImage("Kapa.jpg",5,PAGE_HEIGHT - 45,CENTRE_WIDTH -
50,PAGE_HEIGHT - 800)

self.canv.line(5,PAGE_HEIGHT - 50,PAGE_WIDTH - 5,PAGE_HEIGHT - 50)



# create headings

styles = getSampleStyleSheet()



data1 = []



par1 = Paragraph("This is to the left",styles['Normal'])

data1.append(par1)

self.frameLeft.addFromList(data1, self.canv)



par2 = Paragraph("This is to the middle",styles['Normal'])

data1.append(par2)

self.frameMiddle.addFromList(data1, self.canv)



par3 = Paragraph("This is to the right",styles['Normal'])

data1.append(par3)

self.frameRight.addFromList(data1, self.canv)



# page number

self.canv.saveState()

self.canv.setFontSize(10)

self.canv.drawCentredString(CENTRE_WIDTH,5,"Page : " +
str(self.canv.getPageNumber()))



self.canv.restoreState()





def makeDocument():



doc = coaDocTemplate("c:\riaan.pdf")

styles = getSampleStyleSheet()







Thank you for helping out !!!



Riaan Bekker



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://two.pairlist.net/pipermail/reportlab-users/attachments/20070126/303adcbc/attachment.html


More information about the reportlab-users mailing list