[Zope] OT: Zope/ReportLab/PDF generate left aligned tables

Andreas andreas@ahit.de
Thu, 19 Oct 2000 02:56:29 +0200


Hi,
Is anybody out there using ReportLab PDF library ?

I successfully installed ReportLab and PIL to serve out pdf files with
Zope.
Now I'm in trouble with reportlab.platypus.SimpleDocTemplate ,Table.
I can't figure out how to draw a table left aligned on a PageTemplate.
I can set several styles of table cells but wehrer can I set the
alignment of a table within it's frame?

##################
# myZopeTable.py #
##################
import string
from reportlab.platypus import Image,Table, TableStyle,
SimpleDocTemplate
from reportlab.lib.units import inch, cm
from reportlab.lib import colors
from reportlab.pdfgen.canvas import Canvas
from reportlab.lib.pagesizes import A4, landscape 
from reportlab.pdfgen.textobject import PDFTextObject
from types import *

class buffer:
     def __init__(self):
         self._buffer = []
         self._size = 0

     def write(self,line):
         self._buffer.append(str(line))

     def read(self):
         data = string.join(self._buffer, '')
         return data

     def tell(self):
         return len(self._buffer)

def myPage(canvas,doc):    
        canvas.saveState()
        canvas.setPageCompression(1)
        canvas.setFont('Times-Roman',9)
        canvas.setAuthor('andreas@aHit.de')
        canvas.drawRightString(doc.leftMargin+doc.width,10,"Page %d" %
doc.page)   
        canvas.restoreState()

def helloworld(self,req):

        stream = buffer()
        res=self.SqlWizardQuery()   # ZSQLMethod
        data=[]
        for i in range(len(res)):
            row=res[i]      
            items=[]
            items.append(req.sq+i)
            for j in range(len(row)):
                items.append(row[j])        
            data.append(items)
        t=Table(data)
       
t.setStyle(TableStyle([('INNERGRID',(0,0),(-1,-1),0.25,colors.black),                               
                               ('BOX',(0,0),(-1,-1),2.0,colors.black),
                               ('ALIGN',(0,0),(-1,0),'CENTER'),
                               ('ALIGN',(0,1),(0,-1),'RIGHT'),
                               ('FONTSIZE',(0,0),(-1,0),8),
                              ]))
        lst = []
        lst.append(t)
        doc = SimpleDocTemplate(stream, pagesize=landscape(A4),
leftMargin=2*cm, rightMargin=2*cm, topMargin=2.5*cm, bottomMargin=2*cm
,showBoundary=1)     
        doc.build(lst,myPage,myPage)     
        return stream.read()


-- 
_________________________________________________________
Andreas Heckel                            andreas@aHIT.de