Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
fpdf star character issue
#1
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.
Reply
#2
You define your asterisk as unicode "\u2B50" But the message says something about using latin-1. What happens if you define star = "*" ?
Reply
#3
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.
Reply
#4
I think I will do the image thing. Much easier
Thanks for your help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 902 Oct-25-2023, 09:09 AM
Last Post: codelab
  Label Maker FPDF, Reportlab jamesaarr 1 2,603 Aug-09-2021, 11:57 PM
Last Post: Pedroski55
  [solved] unexpected character after line continuation character paul18fr 4 3,294 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  fpdf orientation not working properly KatMac 1 3,259 May-02-2021, 10:47 AM
Last Post: Pedroski55
  fpdf adding a new font to my report KatMac 0 2,122 Apr-23-2021, 02:19 PM
Last Post: KatMac
  ModuleNotFoundError: No module named 'fpdf' KatMac 4 11,019 Apr-19-2021, 01:23 PM
Last Post: KatMac
  How to scrape and count star rating using Selenium and Python? celinafregoso99 1 3,265 Feb-15-2021, 02:45 PM
Last Post: kashcode
  FPDF question DPaul 2 2,696 Oct-27-2020, 08:26 AM
Last Post: DPaul
  SyntaxError: unexpected character after line continuation character siteshkumar 2 3,110 Jul-13-2020, 07:05 PM
Last Post: snippsat
  Why there is a star inside randn? new_to_python 4 2,442 Mar-06-2020, 04:45 AM
Last Post: new_to_python

Forum Jump:

User Panel Messages

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