我正在尝试从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')
如何将胡言乱语转换为希伯来语?