简体   繁体   English

fpdf python细胞消失

[英]fpdf python cells disappearing

I created this program in github that converts quizlet flashcards into large printable ones because quizlet has removed that feature.我在 github 中创建了这个程序,它将 quizlet 抽认卡转换为可打印的大型卡片,因为 quizlet 已经删除了该功能。 The one on github works however it doesn't work with larger bits of text. github上的那个可以工作,但是它不适用于较大的文本。 I have changed it to make the font smaller when it doesnt fully fit.我已对其进行了更改,以在字体不完全适合时使其变小。 However the cell would just disappear.然而,细胞会消失。 I thought the font was just zero but that's not the case.我以为字体只是零,但事实并非如此。 Even when trying the way below, cells just vanish.即使尝试下面的方法,细胞也会消失。 As shown here如此处所示

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')

here is the earlier version that changes font size(i am aware there is no check to make sure the font is not 0):这是更改字体大小的早期版本(我知道没有检查以确保字体不为 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')

Try尝试

pdf.cell(105, 74.25, str(words), 1, 1, 'C')

and you might find that you want你可能会发现你想要

words = '\n'.join(list(words))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM