PyFPDF产生垂直文本

问题描述

前一段时间,我将PHP脚本翻译为python,但最近又遇到了一些问题。 (这是生成投票的脚本)

代码

完整代码在这里https://pastebin.com/ULAF1Nh5

打印投票选项(候选人的姓名和政党)的部分在第403行附近:

bazel build //tools:drake_visualizer //manipulation/util:geometry_inspector --define="-DUSE_SYstem_VTK=OFF"`

getoptionHeight函数仅返回给定文本的高度。 WriteHTML函数只是将html文本转换为python文本,并将其写入pdf中:

    #Now we have the text,we calculate how tall it is
    current_option_height = getoptionHeight(current_option_text,left_padding,right_padding)
    #Write the option out
    pdf.set_left_margin(left_margin+left_padding+(current_column*column_width)+oval_column_width)
    pdf.set_xy((left_margin+(current_column*column_width)+left_padding)+oval_column_width,current_column_y+oval_HEIGHT*2)
    WriteHTML(current_option_text)
    print(current_option_text)

问题: 首先,该脚本有效。送入其中的第一篇文章是:

def WriteHTML(html):
    #HTML parser
    html = html.replace('\n',' ')
    a = html.replace('<BR>','\n')
    a = a.replace('</B>','<B>')
    a = a.split('<B>')
    for i in a:
        if a.index(i)%2 == 0:
            #normal
            pdf.set_font('Helvetica','',11.5)
            pdf.write(OPTION_LINE_HEIGHT,i)
        else:
            #Bold
            pdf.set_font('Helvetica','B',i)

(每个选项都是单独编写的)

哪个(如预期)产生:

Perfectly-generated part of the ballot

但是,一旦它绘制了选票的另一部分,它就会开始垂直书写文本:

Even the 2000 Palm Beach County ballots were better

为什么?我该如何解决

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)