PDF Generation With Reportlab

Discussion in 'Python' started by Albert Leibbrandt, Jun 28, 2010.

  1. Hi All

    I am hoping there is someone out there that knows reportlab quite well.
    I posted this on the reportlab mailing list but there is not much
    activity on that list

    I am currently generating a pdf report using reportlab 2.3 and python
    2.5.4. The report has a table that spans multiple pages. My problem is
    that the portions on the table that continues after the first page, is
    starting at a point not defined by me, so it creates a layer over the
    logo which is on each page.
    How do I specify the starting point of each page the table spans ?
    Normally I would use pagebreak and spacers but I cannot figure out how
    to fit this into the table structure. I also looked at using the
    myLaterPages function, but it does not seem that I can do this with the
    canvas.

    Here is a small extract of my current code

    doc = SimpleDocTemplate("test.pdf")
    Story = [Spacer(1, mm * 60)]
    #populate story with first page

    record_data = []
    for var1, var2, var3, var4, var5 in cursor.fetchall():
    Story.append(PageBreak())
    Story.append(Spacer(1, mm * 15))
    Story.append(Paragraph(var1, heading1))
    Story.append(Spacer(1, mm * 5))
    Story.append(Paragraph(var2, description))
    Story.append(Spacer(1, mm * 5))
    record_data.append([Paragraph('Header 1', grid_header),
    Paragraph('Header 2', grid_header), Paragraph('Header 3', grid_header),
    Paragraph('Header 4', grid_header), Paragraph('Header 5', grid_header)])

    record_data.append([Paragraph(var1, grid), Paragraph(var2, grid),
    Paragraph(var3, grid), Paragraph(var4, grid), Paragraph(var5, grid)])

    t = Table(record_data, style=[('GRID', (0, 0), (-1, - 1), 0.5,
    colors.HexColor('#00204E'))], colWidths=[65, 220, 50, 50, 40])
    Story.append(t)

    doc.build(Story, onFirstPage=myFirstPage, onLaterPages=myLaterPages)


    myFirstPage and MyLaterPages are functions that use the canvas to draw
    the page header and footer.

    Any advice would be greatly appreciated.

    Cheers
    Albert
    Albert Leibbrandt, Jun 28, 2010
    #1
    1. Advertising

  2. On 2010/06/30 10:52 AM, Tim Roberts wrote:
    > Albert Leibbrandt<> wrote:
    >
    >> I am hoping there is someone out there that knows reportlab quite well.
    >> I posted this on the reportlab mailing list but there is not much
    >> activity on that list
    >>

    > Never the less, that is the correct forum for this question. The ReportLab
    > mailing list is operated and manned by ReportLab employees. They know the
    > code better than anyone.
    >
    >
    >> I am currently generating a pdf report using reportlab 2.3 and python
    >> 2.5.4. The report has a table that spans multiple pages. My problem is
    >> that the portions on the table that continues after the first page, is
    >> starting at a point not defined by me, so it creates a layer over the
    >> logo which is on each page.
    >> How do I specify the starting point of each page the table spans ?
    >>

    > Are you talking about something more sophisticated than setting the
    > topMargin property in the SimpleDocTemplate constructor? If you have a
    > logo on each page, you'd want your top margin to exclude that logo. The
    > default top margin is 1 inch. If that's not enough, extend it. If you
    > need different margins on different pages, then you need something more
    > sophisticated than SimpleDocTemplate.
    >
    >
    >> Normally I would use pagebreak and spacers but I cannot figure out how
    >> to fit this into the table structure.
    >>

    > Page breaks and spacers are absolutely the wrong way to handle this. Think
    > about this as a Word document. If you want to exclude the logo, you'd
    > change the top margin to protect it.
    >


    Thanks a mil Tim, your reply actually gave me what I was looking for.
    too little sleep on my part ...

    Cheers
    Albert
    Albert Leibbrandt, Jun 30, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John J. Lee
    Replies:
    0
    Views:
    388
    John J. Lee
    Jun 1, 2006
  2. vasudevram
    Replies:
    1
    Views:
    440
    vasudevram
    Oct 4, 2009
  3. Tim
    Replies:
    0
    Views:
    224
  4. Ricardo Pog
    Replies:
    1
    Views:
    399
    Austin Ziegler
    Mar 26, 2008
Loading...

Share This Page