最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - FPDF2 separate styling in table - Stack Overflow

programmeradmin4浏览0评论

Is it possible to separately style column headers and row values? I tried this but it generates same style for both. I am only keen on different font-size and font-color.

from fpdf import FPDF
from fpdf.fonts import FontFace

data = (
    ("First name", "Last name", "Age", "City"),
    ("Jules", "Smith", "34", "San Juan"),
    ("Mary", "Ramos", "45", "Orlando")
)

pdf = FPDF()
pdf.add_page()

pdf.set_font(family="Helvetica", style="B", size=12)

# Table
font_color_header = (0, 0, 0)
font_color_cell = (255, 0, 0)

headings_style = FontFace(color=font_color_header, size_pt=18)
cell_style = FontFace(color=font_color_cell, size_pt=9)

with pdf.table(headings_style=headings_style) as table:
    for data_row in data:
        row = table.row()
        for datum in data_row:
            row.cell(text=datum, style=cell_style)
发布评论

评论列表(0)

  1. 暂无评论