[reportlab-users] Page Numbering without Platypus
Tim Roberts
timr at probo.com
Mon Aug 28 17:36:10 EDT 2006
Rob Schall wrote:
> I'm currently working on a python class which will automatically
> generate contracts for our company. Since they are legal documents, I
> need to ensure the page numbers are at the bottom in the X of Y
> format. However, everything I've found online refers to using platypus
> to make it work. I've made the attempt to do it without, but either
> I'm definatly not very good with reportlab, or I'm just missing
> something. Currently, the program watches the status of each page and
> determines if you are nearing a page end. Once it determines a new
> page is needed, it runs the "footer" function which looks like this:
>
> def footer(self, posX, posY):
> """Show Footer Information"""
>
> width, height = self.c._pagesize
> width -= self.RightMargin + self.LeftMargin
> self.c.drawCentredString(width/2, posY, self.data["footer"])
> print ('setPage%d'%self.pageNumber)
> self.c.beginForm('setPage%d'%self.pageNumber)
> self.c.drawString(width/2,posY-10,"Page 1 of
> %d"%self.c.getPageNumber())
> self.c.endForm()
> self.pageNumber += 1
>
> then a showPage is done and it continues on. Just before the final
> save, i have final function that does:
>
> def pageNumbers(self):
>
> for page in range(1,self.pageNumber):
> print ("setPage%d"%page)
> self.c.doForm("setPage%d"%page)
>
> return 1
>
> Right now, they all appear on the last page. I'm not fully sure why,
> or how to fix this.
I think you have this backwards. The "doForm" will insert the form at
that point. You want to "doForm" at the bottom of each page, and then
create the forms with beginForm after you know the page numbering. The
"doForm" reference will be unknown until the document is complete.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the reportlab-users
mailing list