简体   繁体   中英

write list in pdf file using python

在此处输入图片说明 I am trying to write list of strings in pdf file using below script.

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.

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. 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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