[reportlab-users] doc.topMargin in SimpleDocTemplate

Robin Becker robin at reportlab.com
Mon Nov 14 05:58:26 EST 2011


On 12/11/2011 16:38, Michael Hipp wrote:

> On 10/12/2011 11:33 AM, Michael Hipp wrote:

>> I'm building a simple report like this:

>> doc = SimpleDocTemplate(out, ...)

>> doc.topMargin = 1.0*inch # space for header on 1st page

>>

>> I'd like to change that topMargin to 0.0 in my onLaterPages() routine, but it

>> seems fixed once set. Is it possible to alter it once building has started?

>

> Replying to my own question...

>

> Can anyone assist with this? I need to change the top margin on later pages and

> not print the header.

>

> Thanks,

> Michael

..........

The topMargin is defaulted to 1 inch; however, the page templates and their
frames are pre-built in the SimpleDocTemplate so you will need to mess with them
in your onFirstPage or onLaterPages routine.


I tried this and it seems to work.
#####################################################################
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus.paragraph import Paragraph
from reportlab.platypus.doctemplate import SimpleDocTemplate
from reportlab.platypus import Spacer, PageBreak, Frame

styleSheet = getSampleStyleSheet()
bt = styleSheet['BodyText']
p=[Paragraph('''The concept of an integrated one box solution for advanced voice and
data applications began with the introduction of the IMACS. The
IMACS 200 carries on that tradition with an integrated solution
optimized for smaller port size applications that the IMACS could not
economically address. An array of the most popular interfaces and
features from the IMACS has been bundled into a small 2U chassis
providing the ultimate in ease of installation.''', bt) for i in (0,1,2)]

def onLaterPages(canv,doc):
frameT = Frame(doc.leftMargin, doc.bottomMargin, doc.width, doc.height + 72,
id='normal')
doc.pageTemplate.frames[:] = [frameT]

story=[p[0],Spacer(72,72),p[1],PageBreak(),p[2]]
doc = SimpleDocTemplate('tsimpldoc.pdf')
doc.build(story,onLaterPages=onLaterPages)
#####################################################################
--
Robin Becker


More information about the reportlab-users mailing list