Skip to content

Instantly share code, notes, and snippets.

@bgnori
Created January 4, 2013 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgnori/4452571 to your computer and use it in GitHub Desktop.
Save bgnori/4452571 to your computer and use it in GitHub Desktop.
reportlabのplatypusを使ってtableを描画するサンプル。wrapOnを呼びなさいということ
#!/usr/bin/python
# -*- coding: utf-8 -*-
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib import colors
from reportlab.platypus import Table
pdfmetrics.registerFont(TTFont('IPA Gothic',
'/usr/share/fonts/ipa-gothic/ipag.ttf'))
xmargin = 8.4*mm
ymargin = 8.8*mm
swidth = 48.3*mm
sheight = 25.4*mm
c = canvas.Canvas("/home/nori/Desktop/work/pdf/forDayCare/test.pdf", pagesize=A4)
#c.drawString(xmargin, ymargin, u"どや、pdfやで。reportlab!")
t = Table([['a', 'b'], ['1', '2']])
t.setStyle([('TEXTCOLOR', (0,0), (1,0), colors.red)])
t.wrapOn(c, 100*mm, 100*mm)
t.drawOn(c, 100*mm, 100*mm)
c.showPage()
c.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment