[reportlab-users] Reducing the margin of a table
Robin Becker
robin at reportlab.com
Wed Jun 29 06:40:18 EDT 2005
Claudio Battaglino wrote:
> Hi,
> I'd like to generate a page with a single table with margin = 0.
> That is the table should fill all the page.
> I tried it and the result is in the attachment.
> As you can see I don't have a null margin and between the table and the
> border of the page I've an empty space.
> How can I have a table that fills all the page?
>
......
Unfortunately for reasons bets know only to an earlier iteration of myself it
seems that Frames come with a built in set of paddings and in SimpleDcocTemplate
there's no easy way to get at them. A way round that is to define your own class
and fix up the paddings prior to use eg
##########
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph
from reportlab.lib.units import cm
from reportlab.lib import colors
PAGE_WIDTH = 5.5 * cm
PAGE_HEIGHT = 2.2 * cm
t = Table([['This is a single cell table']],
colWidths=PAGE_WIDTH,rowHeights=PAGE_HEIGHT,
style=TableStyle([
('VALIGN',(0,0),(-1,-1),'BOTTOM'),
('ALIGN',(0,0),(-1,-1),'LEFT'),
('LEFTPADDING',(0,0),(-1,-1), 0),
('RIGHTPADDING',(0,0),(-1,-1), 0),
('BACKGROUND', (0,0), (-1,-1), colors.pink),
('BOX',(0,0),(-1,-1), 0.1, colors.blue),
],
),
)
class MySimpleDocTemplate(SimpleDocTemplate):
def addPageTemplates(self,pageTemplates):
'''fix up the one and only Frame'''
if pageTemplates:
f = pageTemplates[0].frames[0]
f._leftPadding=f._rightPadding=f._topPadding=f._bottomPadding=0
#f._reset()
f._geom()
SimpleDocTemplate.addPageTemplates(self,pageTemplates)
MySimpleDocTemplate('tt.pdf',
pagesize=(PAGE_WIDTH, PAGE_HEIGHT),
bottomMargin=0, topMargin=0, rightMargin=0, leftMargin=0,
showBoundary=1).build([t])
########
--
Robin Becker
More information about the reportlab-users
mailing list