我正在尝试在固定列宽和行高可变的表单元格中添加段落。
问题是当我增加字体大小时,行高不会改变。
第二,如果我不得不写长字符串,则文本会自动分成许多行,但是它们有些重叠。
下面的代码描述问题。
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Frame, Spacer, Image
from reportlab.lib import colors
from reportlab.lib.units import cm, inch
from reportlab.lib.pagesizes import A3, A4, landscape, portrait
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
from reportlab.lib.enums import TA_LEFT, TA_RIGHT, TA_CENTER, TA_JUSTIFY
from reportlab.pdfgen import canvas
SXmargin = 1.5 * cm
DXmargin = 1.5 * cm
def printTitle():
st = ParagraphStyle('Normal')
st.fontSize=30
title = Paragraph("TITLE", st)
data = [[None, title, None, None, title, None]]
titleColumnSize = (doc.pagesize[0]-(SXmargin * 2 + DXmargin * 2)) /2
tbl = Table(data, [SXmargin, titleColumnSize, DXmargin, SXmargin,
titleColumnSize, DXmargin],None)
tbl.hAlign = 'CENTER'
tbl.vAlign = 'TOP'
tblStyle = TableStyle([('TEXTCOLOR',(0,0),(-1,-1),colors.black),
('VALIGN',(0,0),(-1,-1),'MIDDLE'),
('LINEBELOW',(0,0),(-1,-1),1,colors.white),
('INNERGRID',(2,0),(3,0),1,colors.black),
('INNERGRID',(0,0),(-1,-1),1,colors.black),
('BOX',(0,0),(-1,-1),1,colors.black)])
tblStyle.add('BACKGROUND',(0,0),(-1,-1),colors.white)
tblStyle.add('ALIGN', (1, 0), (1, 0), "CENTER")
tblStyle.add('ALIGN', (4, 0), (4, 0), "CENTER")
tbl.setStyle(tblStyle)
return tbl
pdfReportPages = "test.pdf"
doc = SimpleDocTemplate(pdfReportPages, pagesize=landscape(A4))
elements = []
styles=getSampleStyleSheet()
styleN = styles["Normal"]
elements.append(printTitle())
doc.build(elements)
有人可以帮我解决这些问题吗? 非常感谢 最好的问候