简体   繁体   English

使用python在pdf文件中写入列表

[英]write list in pdf file using python

在此处输入图片说明 I am trying to write list of strings in pdf file using below script. 我正在尝试使用以下脚本在pdf文件中写入字符串列表。

pdf = fpdf.FPDF(format='letter')
pdf.add_page()
pdf.set_font("Arial", size=12)

for i in data:
    pdf.write(5,str(i))
    pdf.ln()
pdf.output("testings.pdf")

But, I am getting error 但是,我遇到了错误

UnicodeEncodeError: 'latin-1' codec can't encode character '\u201c' in position 1548: ordinal not in range(256)

data contain results in string format Can anyone please help me to know how to write results in pdf file, I want to write each string in data list separate page. 数据包含字符串格式的结果,谁能帮助我知道如何将结果写入pdf文件,我想将每个字符串写在数据列表的单独页面中。

Above is data screenshot The length is huge so not inserting all records but list contain text data only 上面是数据屏幕截图,它的长度很大,因此不会插入所有记录,但列表仅包含文本数据

This is because MySQLdb normally tries to encode everythin to latin-1. 这是因为MySQLdb通常尝试将所有内容编码为latin-1。 This can be fixed by executing the following commands right after you've etablished the connection: I also have the same problem Python MySQLdb module. 建立连接后,可以通过执行以下命令来解决此问题:我也遇到同样的问题Python MySQLdb模块。 Since MySQL will let you store just about any binary data you want in a text field regardless of character set, I found my solution here Link 由于MySQL将让您刚才保存你在无论字符集的文本字段需要的任何二进制数据,我发现我的解决方案在这里链接

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

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