使用希伯来语文本读取CSV文件并使用python写入PDF文件

时间:2017-05-11 14:17:29

标签: python csv pdf hebrew

我正在尝试从csv文件中读取表格并将其写入PDF文件,但希伯来文本在PDF文件中显示为乱码。当我尝试添加encode('utf-8')时出现错误。

这是代码:

for line in list(open('aw.csv', encoding = "iso-8859-1")):
    if len(line.strip()) != 0:
        line = line.strip()
        column = line.split(',')
        if numrow == 0:
            html_out1 = html_out1 + '<thead><tr><th width="10%">' + column[0] + '</th><th width="10%" >' + column[1] + '</th><th width="40%">' + column[2] + '</th><th width="40%">' + column[3] + '</th><th width="20%">' + column[4] + '</th></tr></thead>'
        else:
            print(column[4].encode('utf-8'))
            html_out = html_out + '<tr><td>' + column[0] + "</td><td>" + column[1] + "</td><td>" + column[2] + "</td><td>" + column[3] + "</td><td>" + column[4] + "</td></tr>"
        numrow = numrow + 1
from fpdf import FPDF, HTMLMixin


class MyFPDF(FPDF, HTMLMixin):
    pass

html = html +html_out1 + html_out + "</tbody> </table>"
pdf = MyFPDF()
# First page
pdf.add_page()
pdf.write_html(html)
pdf.output('html.pdf', 'F')

如何将胡言乱语转换为希伯来语?

0 个答案:

没有答案