[reportlab-users] Fwd: problem in total page number

Dhara Shah dharashah05 at gmail.com
Wed Jul 4 06:21:33 EDT 2007


---------- Forwarded message ----------
From: Dhara Shah <dharashah05 at gmail.com>
Date: Jul 4, 2007 3:50 PM
Subject: problem in total page number
To: reportlab-users at reportlab.com.

Hello

I have tried the following code to implement total page number in
Tiny-Report.But it is not working.

HTH
Henning


#!/bin/env python
# -*- coding: iso-8859-1 -*-
#
#Copyright Triestram&Partner GmbH 2003
#
# @AUTHOR Henning von Bargen
#
# @SINCE 13.10.2003
#
# @VERSION 0.1 $$ Revision $$

#


__version__=''' $$ Revision $$ '''


__doc__="""Vorlage für Tabellarische Berichte.


Die hier definierten Klassen definieren das grundsätzliche Layout
der Berichte (z.B. Kopf- und Fusszeilen).
"""


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


from reportlab.lib.units import inch,cm,mm
from reportlab.lib import colors
from reportlab.lib import pagesizes
from reportlab.lib.styles import getSampleStyleSheet


import os.path


imagePath="../images"


class EinspaltigTemplate(PageTemplate):
def __init__(self, id, pageSize):
self.numPages = 0
self.pageWidth = pageSize[0]
self.pageHeight = pageSize[1]


# Seitenrand links/rechts 2cm, oben 2cm, unten 1.5cm,
frame1 = Frame(20*mm,
15*mm,
self.pageWidth - 40*mm,

self.pageHeight - 35*mm, id='normal')
PageTemplate.__init__(self, id, [frame1]) # note lack of onPage


def afterDrawPage(self, canvas, doc):
# Titel und Seitenzahl in der Kopfzeile ausgeben
y = self.pageHeight - 15*mm
canvas.saveState()
canvas.drawImage
(os.path.join(imagePath,'mylogo.jpg'),20*mm,
self.pageHeight-14*mm)
canvas.setFont('Helvetica', 12)
canvas.drawString(60*mm, y+8, "My document title")
canvas.line
(20*mm, y, self.pageWidth - 20*mm, y)
canvas.setFont('Helvetica', 8)
canvas.drawRightString(self.pageWidth - 20*mm, y+8, "Page %(page)d
of %(numpages)d" % { "page":canvas.getPageNumber
(),
"numpages":doc.numPages})
canvas.restoreState()


class StandardDocTemplate(BaseDocTemplate):
"""Hier wird das Standardlayout definiert.


Bemerkenswert bei diesem DocTemplate ist, dass die Gesamtseitenzahl
berechnet wird
und in der Kopzeile ausgegeben werden kann.


Sauberer wäre es eigentlich, ein IndexingFlowable zu verwenden,
dass als allerletztes Element hinzugefügt wird.
"""


def progresshandler(self, what, arg):
if what in ["PASS", "PAGE"]:
print what, arg
#print "numPages=%d" % self.numPages

if what=='STARTED':
self._lastnumPages = self.numPages


def afterInit(self):
# Standard: ohne Deckblatt
self.addPageTemplates(EinspaltigTemplate('Einspaltig',
self.pagesize))


#just playing
self.numPages = 1
self._lastnumPages = 0
self.setProgressCallBack(self.progresshandler)


def afterPage(self):
"""This is called after page processing, and
immediately after the afterDrawPage method
of the current page template."""

self.numPages = max(self.canv.getPageNumber(), self.numPages)


def _allSatisfied(self):
"""Eine unsaubere Implementierung, aber bevor wir jetzt anfangen mit
Cross-Referenzen etc.
machen wir es lieber so.
Called by multi-build - are all cross-references resolved?

"""
if self._lastnumPages < self.numPages:
return 0
return BaseDocTemplate._allSatisfied(self)


Regards,


Clifford Ilkay
Dinamis Corporation
3266 Yonge Street, Suite 1419
Toronto, Ontario
Canada M4N 3P6


Tel: 416-410-3326



Can u give me some more details on this.
With this mail I m sending report which is generated using this code.

--
Dhara Shah
Application Engineer,
Tiny ERP INDIA(Belgium).

You can't wait for inspiration. You have to go after it with a club.


--
Dhara Shah
Application Engineer,
Tiny ERP INDIA(Belgium).

You can't wait for inspiration. You have to go after it with a club.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20070704/34db4344/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tmphN3mvp.pdf
Type: application/pdf
Size: 9958 bytes
Desc: not available
Url : <http://two.pairlist.net/pipermail/reportlab-users/attachments/20070704/34db4344/attachment-0001.pdf>


More information about the reportlab-users mailing list