我在github中创建了这个程序,将quizlet闪存卡转换为可打印的大卡,因为quizlet已经删除了该功能。在github上的那个可以工作,但是它不能处理更大的文本。我已经改变了它,使字体更小,当它不完全适合。然而,细胞就会消失。我以为字体只是零,但事实并非如此。即使在下面的路上,细胞也会消失。如图所示
from fpdf import FPDF
import os, math, re, numpy
def group_words(s, n):
words = s.split()
for i in range(0, len(words), n):
yield ' '.join(words[i:i+n])
def printcell(text):
#105 is the width of 1 cell
width = pdf.get_string_width(text)
pdf.set_font("Japanese", size = fontsize)
if(width >= 104):
pdf.set_font("Japanese", size = fontsize-5)
print("splitting")
words = numpy.array(list(group_words(text,3)))
print(words)
words.join('\n')
print(words)
pdf.cell(105, 74.25, words, 1, 1, 'C')
else:
pdf.cell(105, 74.25, text, 0, 1, 'C')下面是更改字体大小的早期版本(我知道没有检查以确保字体不是0):
def printcell(text):
while(pdf.get_string_width(text)>105):
if (counter == fontsize):
pass
else:
pdf.set_font("Japanese", size = fontsize-counter)
counter+=1
pdf.cell(105, 74.25, text, 0, 1, 'C')发布于 2022-07-23 08:54:46
试一试
pdf.cell(105, 74.25, str(words), 1, 1, 'C')你可能会发现你想
words = '\n'.join(list(words))https://stackoverflow.com/questions/73087436
复制相似问题