Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
fpdf star character issue

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
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.
You define your asterisk as unicode "\u2B50" But the message says something about using latin-1. What happens if you define star = "*" ?
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.
I think I will do the image thing. Much easier
Thanks for your help.

Possibly Related Threads…
Thread Author Replies Views Last Post
  [solved] unexpected character after line continuation character paul18fr 4 143 Yesterday, 03:22 PM
Last Post: deanhystad
  fpdf orientation not working properly KatMac 1 289 May-02-2021, 10:47 AM
Last Post: Pedroski55
  fpdf adding a new font to my report KatMac 0 213 Apr-23-2021, 02:19 PM
Last Post: KatMac
  ModuleNotFoundError: No module named 'fpdf' KatMac 4 695 Apr-19-2021, 01:23 PM
Last Post: KatMac
  How to scrape and count star rating using Selenium and Python? celinafregoso99 1 468 Feb-15-2021, 02:45 PM
Last Post: kashcode
  FPDF question DPaul 2 391 Oct-27-2020, 08:26 AM
Last Post: DPaul
  SyntaxError: unexpected character after line continuation character siteshkumar 2 837 Jul-13-2020, 07:05 PM
Last Post: snippsat
  Why there is a star inside randn? new_to_python 4 891 Mar-06-2020, 04:45 AM
Last Post: new_to_python
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 975 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  Installing FPDF Batman 3 4,078 Jun-04-2019, 04:58 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020