[reportlab-users] Forcing doc templates to use pagesize?

Dinu Gherman reportlab-users@reportlab.com
Sat, 10 May 2003 11:12:46 +0200


Hi,

does anybody understand why the following simple code does *not*
create a rectangular page of size 10x10 cm, but a portrait A4 one,
no matter what pagesize I'm passing to the document template?

Thanks,

Dinu


#-------------------------------------------------------------------
# test.py

import unittest

from reportlab.lib.units import cm
from reportlab.platypus.flowables import Spacer
from reportlab.platypus.doctemplate import PageTemplate, BaseDocTemplate
from reportlab.platypus.frames import Frame


def handlePage(canvas, doc):
     pass


class DocTemplate(BaseDocTemplate):
     def __init__(self, filename, **kw):
         apply(BaseDocTemplate.__init__, (self, filename), kw)
         f = Frame(1*cm, 1*cm, 8*cm, 8*cm, id='f')
         pt = PageTemplate('RectPage', [f], handlePage)
         self.addPageTemplates(pt)


class TestRectangularPage(unittest.TestCase):
     def test1(self):
         size = (10*cm, 10*cm)
         doc = DocTemplate('test.pdf', pagesize=size, showBoundary=1)
         story = [Spacer(10, 0)]
         doc.build(story)


if __name__ == '__main__':
     unittest.main()
#-------------------------------------------------------------------


--
Dinu C. Gherman
......................................................................
"They made a desert and called it peace." (Tacitus)