[reportlab-users] Accessing page data in onPageEnd

Chris Foster outofthenet at gmail.com
Thu Mar 22 11:23:45 EDT 2007


I asked a similar question about a week ago. My solution seems crude, but
it works. I added an ActionFlowable where I can stick the data into the
"story" in context and a new doctemplate handler to populate a list where
the indexes are the page numbers, then I can pick out the data in the page
events. Seems a little messy, but I've committed my employer to ReportLab
and just needed this to work ASAP. I'm still getting up to speed on Python,
so please feel free to show me a better way.

story.append(lpmdoctemplate.Savestuff([rec['FULL_NAME'],
rec['LICENSE_NO']]))

class Savestuff(ActionFlowable):
def __init__(self,vals):
ActionFlowable.__init__(self,('savestuff', vals))

class LpmDocTemplate(BaseDocTemplate):
pageinfo = []

def handle_savestuff(self,vals):
self.pageinfo.append(vals)
if len(self.pageinfo) < self.page:
previous = self.pageinfo[len(self.pageinfo)-2][1]
for index in range(len(self.pageinfo), self.page):
self.pageinfo.insert(index-1, previous)

class CertExtraPage(PageTemplate):
def afterDrawPage(self, canvas, doc):
...
canvas.drawString(0.2*inch, 9.3*inch, doc.pageinfo[index][0])
canvas.drawString(6.1*inch, 9.3*inch, doc.pageinfo[index][1])

On 3/21/07, Chris Wilson <cwilson at nswrdn.com.au> wrote:

>

> Hi All,

>

> I am rendering a document using the BaseDocTemplate. The document uses

> tables containing data of a variable size and often these tables span

> multiple pages, and I don't necessarily know where exactly in the table

> the run onto the next page will occur during the build(). I am using the

> onPageEnd event to draw onto the current canvas some text at the top and

> bottom of each page. My issue is that the text I want drawn relates to

> whatever text was placed in the table on the page currently being

> rendered.

>

> Is it possible to in the onPageEnd method to pull from the canvas or

> document the information that has just been rendered onto that page (or

> to save while preparing the flowables the information in a way that can

> be easily accessed int the onPageEnd during the document build()) so

> that I can determine what the text I am need to draw on the page during

> the onPageEnd method is?

>

> I understand that this question is potentially vague, and I apologies

> for this. I am just not sure how to better describe or phrase what I am

> doing.

>

> Thanks in advance for any help.

>

> Regards,

>

> Chris Wilson

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users

>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20070322/a87ff1c4/attachment.htm>


More information about the reportlab-users mailing list