[reportlab-users] UTF8 Encoded Strings
    Rich Shepard 
    rshepard at appl-ecosys.com
       
    Wed Oct 31 15:21:54 EDT 2007
    
    
  
On Wed, 31 Oct 2007, Rich Shepard wrote:
>  Attached is the totally re-written script to produce the page without
> using platypus,
   Now it is.
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.pdfgen import canvas
from reportlab.platypus.tables import Table, TableStyle, CellStyle, LongTable
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')]
ratingHead = """Importance                                   
                    Value                                   Definition
                    """
ratingTab = """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."""
Title = "Economic Components"
width, height = LETTER
  
def econRun():
  pg = canvas.Canvas('ecoForm.pdf', pagesize=LETTER)
  textobject = pg.beginText()
  textobject.setTextOrigin(3*inch,10.5*inch)
  textobject.setFont('Helvetica-Bold', 13)
  textobject.textOut(Title)
  textobject.setFont('Times-Roman', 9)
  x = 0
  y = 0.5*inch
  textobject.moveCursor(x, y)
  margin = textobject.getX()
  for pairs in pairData:
    textobject.textOut(pairs[0])
    textobject.setXPos(90)
    textobject.textLine(pairs[1])
    textobject.setXPos(-90)
  # Write the instructions
  textobject.moveCursor(-2*inch,54)
  textobject.textLines(instructPara)
  # Write rating table
  textobject.moveCursor(0,-2.75*inch)
  X = textobject.getX()
  Y = textobject.getY()
  textobject.setTextOrigin(X, Y)
  pg.setLineWidth(0.01*inch)        # Top line of table
  pg.line(X,Y,4.5*inch,Y)
  
  textobject.moveCursor(0,12)
  textobject.textLines(ratingHead)  # Column headings
  X = textobject.getX()
  Y = textobject.getY()
  textobject.setTextOrigin(X,Y)
  pg.line(X,Y-20,4.5*inch,Y-20)     # Line under column headings
  textobject.moveCursor(8,35)
  textobject.textLines(ratingTab)
  X = textobject.getX()
  Y = textobject.getY()
  textobject.setTextOrigin(X,Y)
  pg.line(X-8,Y-1*inch,4.5*inch,Y-1*inch)     # Line under table
  pg.drawText(textobject)
  
  pg.showPage()
  pg.save()
if __name__ == "__main__":
  econRun()
    
    
More information about the reportlab-users
mailing list