fpdf star character issue - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: fpdf star character issue (/thread-33518.html) |
fpdf star character issue - KatMac - May-01-2021 Hello, I have a database with a number of fields and 1 of the fields is Rating. This field contains the word, One, Two, Three, Four or Five. Each time I loop through a record, I want the Rating string to be converted to x number of stars based on the string passed to it. I have written a function that does this. The function displays the correct # of stars if I am sending the output to my VSC Terminal. When I try convertting it to a pdf (using fpdf) I receive an error: # partial code in my fpdf function tmp = star_rating(row[7]) pdf.cell(25, 0, tmp, align="L", border=0) # partial code in star_rating() star = "\u2B50" if string == "Three": times = 3 etc. return star * times UnicodeEncodeError: 'latin-1' codec can't encode characters in position 1275-1278: ordinal not in range(256)The font I am using is Arial. RE: fpdf star character issue - ibreeden - May-01-2021 You define your asterisk as unicode "\u2B50" But the message says something about using latin-1. What happens if you define star = "*" ?
RE: fpdf star character issue - bowlofred - May-01-2021 You are asking for a unicode character \u2B50 that is outside the latin-1 encoding used by fpdf. I think the fonts it uses don't have characters outside latin-1.Either change it to an image and stick an image there every time, or switch to a latin-1 compatible character. RE: fpdf star character issue - KatMac - May-01-2021 I think I will do the image thing. Much easier Thanks for your help. |