Python 我的字体在哪里重置?

Python 我的字体在哪里重置?,python,pdf-generation,reportlab,Python,Pdf Generation,Reportlab,我正在写一个小程序来制作一堆宾果游戏卡 from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import landscape, letter from reportlab.lib.units import inch import random def set_ranges(): r = { "b": [1, 15, 0], "i": [16, 30, 0],

我正在写一个小程序来制作一堆宾果游戏卡

from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import landscape, letter
from reportlab.lib.units import inch
import random


def set_ranges():
    r = {
        "b": [1, 15, 0],
        "i": [16, 30, 0],
        "n": [31, 45, 0],
        "g": [46, 60, 0],
        "o": [61, 75, 0]
    }
    return r

def set_canvas():
    c = canvas.Canvas("bingo.pdf")
    c.setPageRotation(90)
    c.setFont('Helvetica-Bold', 14)
    print type(c)
    return c

def print_card(ranges, canvas):
    # Set a page gutter
    gutter = 1 * inch
    x = gutter
    y = 8.5 * inch - 2 * gutter
    # First draw the letters themselves
    for letter in "bingo":
        canvas.drawString(x, y, letter)
        # Print X and Y to troubleshoot
        # print('%s, %d, %d' % (letter, x, y))
        # Add the X value for each letter to the dictionary
        ranges[letter][2] = x
        x = x + 1 * inch
    y_reset = y - 1 * inch
    # Then pull the numbers for each square
    for letter in "bingo":
        row = random.sample(range(ranges[letter][0], ranges[letter][1] + 1), 5)
        if letter == "n":
            row[2] = "FREE"            
        x = ranges[letter][2]
        y = y_reset
        for col in row:
            # Print X and Y to troubleshoot
            # print('%d, %d, %d' % (col, x, y))
            canvas.drawString(x, y, str(col))
            y = y - 1 * inch
    canvas.save()
我还有一些工作要做,自由应该是中心的!我需要画线,但这基本上是可行的。我做r=set_ranges和c=set_canvas,然后对范围1,25中的I:print_cardr,c创建一个包含基本卡片的PDF


但在第一页之后,字体不再粗体。它将在何处重置?

您正在使用哪个版本的ReportLab?版本1.1.0 2012-12-18有一个错误,有时在呈现之前会重置字体…

来自reportlab参考:

def saveself:保存并关闭文件中的PDF文档。如果有 是自动执行ShowPage的当前数据。此后 操作画布不得进一步使用


所以你的代码工作起来很奇怪。您可以生成所有的表,然后调用canvas.save。

如果您介意的话,这是最主要的最终产品:我有2.6,但我要说的是有一个bug,因为这是唯一的解释。