[reportlab-users] Positioning Paragraphs and Tables Precisely

Rich Shepard rshepard at appl-ecosys.com
Fri Oct 12 19:40:28 EDT 2007


On Fri, 12 Oct 2007, Andy Robinson wrote:


> If you need further help on this, please replace all the sqlite

> references with canned data arrays in the script and I could then help

> you massage it a bit.


Andy,

What the heck, just made it self-contained.

If I use the enum, table is centered. If I use the string, it's left
aligned. Must be me.

Can I adjust the vertical position of the table on the page?

I assume that for adjusting the spacing of the rows I change the leading
in the table style.

When I get this properly positioned, I'll have more text to add, plus
another table, and a small black box that will fill in one of the OMR
bubbles. That's why I want to learn how to precisely position everything on
the page.

I greatly appreciate your help, and that of everyone else. Stepping back
and starting from scratch worked much better for me than did trying to fit
my report in a pre-existing example.

Rich

--
Richard B. Shepard, Ph.D. | The Environmental Permitting
Applied Ecosystem Services, Inc. | Accelerators(TM)
<http://www.appl-ecosys.com> Voice: 503-667-4517 Fax: 503-667-8863
-------------- next part --------------
#!/usr/bin/env python

from reportlab.platypus import Spacer, SimpleDocTemplate, Table, TableStyle
from reportlab.platypus.paragraph import Paragraph
from reportlab.lib import colors
from reportlab.lib.units import inch, cm
from reportlab.lib.pagesizes import LETTER, landscape, portrait
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT

data = [(u'Jobs', u'Tax base'),
(u'Jobs', u'Infrastructure'),
(u'Jobs', u'Schools'),
(u'Jobs', u'Housing'),
(u'Jobs', u'Medical care'),
(u'Jobs', u'Sustainability'),
(u'Jobs', u'Traffic volume'),
(u'Tax base', u'Infrastructure'),
(u'Tax base', u'Schools'),
(u'Tax base', u'Housing'),
(u'Tax base', u'Medical care'),
(u'Tax base', u'Sustainability'),
(u'Tax base', u'Traffic volume'),
(u'Infrastructure', u'Schools'),
(u'Infrastructure', u'Housing'),
(u'Infrastructure', u'Medical care'),
(u'Infrastructure', u'Sustainability'),
(u'Infrastructure', u'Traffic volume'),
(u'Schools', u'Housing'),
(u'Schools', u'Medical care'),
(u'Schools', u'Sustainability'),
(u'Schools', u'Traffic volume'),
(u'Housing', u'Medical care'),
(u'Housing', u'Sustainability'),
(u'Housing', u'Traffic volume'),
(u'Medical care', u'Sustainability'),
(u'Medical care', u'Traffic volume'),
(u'Sustainability', u'Traffic volume')]

def getHeading():
stylesheet=getSampleStyleSheet()
headingStyle = stylesheet['Heading3']
h = Paragraph("Economic Components", headingStyle)
return h

def getTable():
t = Table(data,hAlign='LEFT')
return t

def makeTableStyles():
tStyles = []
tStyles.append(TableStyle([('ALIGN', (0,0), (-1,-1), 'LEFT'),
('FONT', (0,0), (-1,-1), 'Helvetica', 10, 11)]))
return tStyles

def run():
doc = SimpleDocTemplate('ecoForm.pdf', pagesize=(8.5*inch, 11*inch), showBoundary=0)
tStyles = makeTableStyles()
story = []
story.append(Spacer(0,-1*inch))
p = getHeading()
story.append(p)

for style in tStyles:
e = getTable()
e.setStyle(style)
story.append(e)
doc.build(story)

if __name__ == "__main__":
run()







More information about the reportlab-users mailing list