我在python 2.7中使用reportlab 3.1.44 这是使用表中段落的代码。
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.rl_config import defaultPageSize
from reportlab.lib.units import inch
from reportlab.lib.styles import ParagraphStyle
from reportlab.platypus.tables import Table, TableStyle
from reportlab.lib import colors
from reportlab.lib.colors import Color
styles = getSampleStyleSheet()
def make_report():
doc = SimpleDocTemplate("hello.pdf")
story = []
style = styles["Normal"]
ps = ParagraphStyle('title', fontSize=20)
p1 = "here is some paragraph to see in large font"
data = []
table_row = [Paragraph(p1, ps),\
Paragraph(p1, ps)\
]
data.append(table_row)
t1 = Table(data)
t1.setStyle(TableStyle([\
('GRID', (0,0), (-1,-1), 0.25, colors.red, None, (2,2,1)),\
]))
story.append(t1)
doc.build(story)
if __name__ == "__main__":
make_report()
字体大时有两个问题。
我怎样才能解决这个问题?
这两个问题实际上是由同一个问题引起的,即
Paragraph
的高度。表格单元格由决定行高的行距决定。同时空白的缺乏也造成了它的行距。在Reportlab中,行距是根据文档使用
leading
样式属性设置的。因此,正确的代码版本将使用:
结果是:
相关问题 更多 >
编程相关推荐