[reportlab-users] Left Margin Too Wide

Rich Shepard rshepard at appl-ecosys.com
Mon Oct 29 19:48:30 EDT 2007

The attached code compiles and prints. However, everything is centered on
the paper instead of left-aligned. I've not figured out how to correct this.

I should try to define a frame along the left half of the paper, and this
might obviate the need to make the page image narrower than the physical
paper. I need the room on the right because that's where a pre-printed form
is located.


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, ParagraphStyle
from reportlab.lib.enums import TA_LEFT, TA_CENTER, TA_RIGHT

pairData = [(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')]

ratingData = [('Importance Value', 'Definition'),
('1', 'Equal importance'),
('3', 'Weak importance of one over the other'),
('5', 'Strong importance of one over the other'),
('7', 'Demonstrated importance of one over the other'),
('9', 'Absolute importance of one over the other'),
('2, 4, 6, 8', 'Intermediate values between the two adjacent definitions')]

instructPara = "Using the table below, determine your preference for either the first \
item of the pair (on the left), or the second (on \
the right). Use the rating table to determine the \
strength of your preference, then fully fill in the \
rectangle for that preference strenth on the same \
line as the component pairs. If you prefer the \
second more than the first, also completely fill in \
the last box on the right."

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

def getTable():
t = Table(pairData,hAlign='RIGHT')
return t

def getTable2():
r = Table(ratingData,hAlign='CENTER')
return r

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

def makeScoreStyles():
sStyles = []
sStyles.append(TableStyle([('ALIGN', (0,0), (0,-1), 'CENTER'),
('ALIGN', (1,0), (1,0), 'CENTER'),
('ALIGN', (1,1), (1,-1), 'LEFT'),
('FONT', (0,0), (0,1), 'Times-Roman', 10, 11),
('FONT', (1,0), (-1,-1), 'Helvetica', 9, 10),
('LINEABOVE', (0,0), (-1,0), 1, colors.black),
('LINEBELOW', (0,0), (-1,0), 1, colors.black)]))
return sStyles

def run():
doc = SimpleDocTemplate('ecoForm.pdf', pagesize=(5.5*inch, 11.5*inch), showBoundary=0)
tStyles = makeTableStyles()
sStyles = makeScoreStyles()
story = []
h1 = getHeading()

for style in tStyles:
e = getTable()

story.append(Spacer(0, 0.25*inch))

paraStyle = stylesheet['Normal']
p = Paragraph(instructPara, paraStyle)

story.append(Spacer(0, 0.25*inch))

for style in sStyles:
f = getTable2()


if __name__ == "__main__":

More information about the reportlab-users mailing list