flickrに表示されている特定のフォームにカスタマイズ可能なflowableを必要としないというdugresに同意します。Table と TableStyle を使用するだけで、仕事を遂行できます。
reportlab に深く入り込む前に考慮すべきことは、テーブルが長すぎて次のページに移動しないことです。次に、テーブルスタイルを手動で編集する必要があります。次のページの表の SPAN セルはエラーを返します。ただし、1 ページのソリューションの場合は、reportpdf が適切なオプションです。
ファンシーな出力、素敵なグラフィック効果。ダグレスが提案したことに従って行う必要があります。
テーブルの開発に関するキックスタート コードの場合:
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4, cm
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import Paragraph, Table, TableStyle
from reportlab.lib.enums import TA_JUSTIFY, TA_LEFT, TA_CENTER
from reportlab.lib import colors
width, height = A4
styles = getSampleStyleSheet()
styleN = styles["BodyText"]
styleN.alignment = TA_LEFT
styleBH = styles["Normal"]
styleBH.alignment = TA_CENTER
def coord(x, y, unit=1):
x, y = x * unit, height - y * unit
return x, y
# Headers
hdescrpcion = Paragraph('''<b>descrpcion</b>''', styleBH)
hpartida = Paragraph('''<b>partida</b>''', styleBH)
hcandidad = Paragraph('''<b>candidad</b>''', styleBH)
hprecio_unitario = Paragraph('''<b>precio_unitario</b>''', styleBH)
hprecio_total = Paragraph('''<b>precio_total</b>''', styleBH)
# Texts
descrpcion = Paragraph('long paragraph', styleBH)
partida = Paragraph('1', styleN)
candidad = Paragraph('120', styleN)
precio_unitario = Paragraph('$52.00', styleN)
precio_total = Paragraph('$6240.00', styleN)
data= [[hdescrpcion, hcandidad,hcandidad, hprecio_unitario, hprecio_total],
[partida, candidad, descrpcion, precio_unitario, precio_total]]
table = Table(data, colWidths=[2.05 * cm, 2.7 * cm, 5 * cm,
3* cm, 3 * cm])
table.setStyle(TableStyle([
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0,0), (-1,-1), 0.25, colors.black),
]))
c = canvas.Canvas("a.pdf", pagesize=A4)
table.wrapOn(c, width, height)
table.drawOn(c, *coord(1.8, 9.6, cm))
c.save()