[reportlab-users] Table and document widths
Will Newton
reportlab-users@reportlab.com
Tue, 6 Jan 2004 13:32:04 +0000
--IJpNTDwzlM2Ie8A6
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Tue, Jan 06, 2004 at 01:12:32PM +0000, Robin Becker wrote:
> >
> ..... can you create a simple example showing the effect and post it to
> the list or direct to me.
I have attached a reasonably simple example. The second table is
noticeably wider.
--IJpNTDwzlM2Ie8A6
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="reportlab_tables.py"
import reportlab.lib.colors as colors
import reportlab.lib.styles
import reportlab.platypus
elements = []
styles = reportlab.lib.styles.getSampleStyleSheet()
doc = reportlab.platypus.SimpleDocTemplate("test.pdf")
table_width = doc.width
style = styles["Normal"]
text1 = """Blah
Blah
Blah"""
text2 = """Foo
Shoe
Moo"""
text3 = """Blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah"""
para1 = reportlab.platypus.XPreformatted(text1, style)
para2 = reportlab.platypus.XPreformatted(text2, style)
para3 = reportlab.platypus.Paragraph(text3, style)
table_data = [[para1, para2]]
table1 = reportlab.platypus.Table(table_data)
table2 = reportlab.platypus.Table(table_data, [table_width/2, table_width/2])
style_data = [("BOX", (0, 0), (-1, -1), 1, colors.black)]
table_style = reportlab.platypus.TableStyle(style_data)
table1.setStyle(table_style)
table2.setStyle(table_style)
elements.append(table1)
elements.append(para3)
elements.append(table2)
doc.build(elements)
--IJpNTDwzlM2Ie8A6--