reportlab の Table の表示位置をコントロールする
table_position.py
#! /usr/bin/python
# ------------------------------------------------------------------
# table_position.py
#
# Feb/11/2018
# ------------------------------------------------------------------
from reportlab.lib.pagesizes import A4
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import mm
from reportlab.lib import colors
from reportlab.lib.styles import ParagraphStyle
from reportlab.pdfgen import canvas
from reportlab.platypus import Image, Paragraph, Table
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.cidfonts import UnicodeCIDFont
# ------------------------------------------------------------------
fontname_g = "HeiseiKakuGo-W5"
pdfmetrics.registerFont(UnicodeCIDFont(fontname_g))
cc = canvas.Canvas('example.pdf', pagesize=A4)
width, height = A4
cc.setFont("HeiseiKakuGo-W5", 16)
str_out = "こんにちは"
cc.drawString(100, 730, str_out)
data = [["テスト", 2, 3], ["日本語", 1, 3], [3, 2, 10]]
table = Table(data, colWidths=20*mm)
table.setStyle([("VALIGN", (0,0), (-1,-1), "MIDDLE"),
("ALIGN", (0,0), (-1,-1), "CENTER"),
('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
('BOX', (0, 0), (-1, -1), 0.25, colors.black),
('FONT', (0, 0), (-1, -1), "HeiseiKakuGo-W5", 16),
])
#
table.wrapOn(cc, width, height)
#
table.drawOn(cc, 140*mm, 250*mm)
table.drawOn(cc, 75*mm, 225*mm)
table.drawOn(cc, 10*mm, 200*mm)
#
styles = getSampleStyleSheet()
my_style = styles["Normal"]
my_style.name = "bonlife"
my_style.fontName = "HeiseiKakuGo-W5"
my_style.fontSize=16
ptext = "これはサンプルです。"
pp = Paragraph(ptext, style=my_style)
pp.wrapOn(cc, 70*mm, 50*mm) # size of 'textbox' for linebreaks etc.
pp.drawOn(cc, 50*mm, 190*mm) # position of text / where to draw
cc.showPage()
cc.save()
# ------------------------------------------------------------------
Author And Source
この問題について(reportlab の Table の表示位置をコントロールする), 我々は、より多くの情報をここで見つけました https://qiita.com/ekzemplaro/items/09bd10b02ecbb35c0efa著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .