Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise FPDFUnicodeEncodingException #510

Closed
me-suzy opened this issue Aug 26, 2022 · 2 comments
Closed

raise FPDFUnicodeEncodingException #510

me-suzy opened this issue Aug 26, 2022 · 2 comments

Comments

@me-suzy
Copy link

me-suzy commented Aug 26, 2022

Traceback (most recent call last):
  File "E:\Carte\BB\17 - Site Leadership\alte\Ionel Balauta\Aryeht\Task 1 - Traduce tot site-ul\Doar Google Web\Andreea\Meditatii\Sedinta 20 august 2022\Convert all html to PDF in a single book - BEBE.py", line 281, in <module>
    save_to_pdf("c:\\Folder5\\")
  File "E:\Carte\BB\17 - Site Leadership\alte\Ionel Balauta\Aryeht\Task 1 - Traduce tot site-ul\Doar Google Web\Andreea\Meditatii\Sedinta 20 august 2022\Convert all html to PDF in a single book - BEBE.py", line 246, in save_to_pdf
    pdf.write_html(text=f'<p class="text_obisnuit2">{content[0]}</p>')
  File "C:\Users\Castel\AppData\Roaming\Python\Python310\site-packages\fpdf\html.py", line 736, in write_html
    h2p.feed(text)
  File "C:\Program Files\Python39\lib\html\parser.py", line 110, in feed
    self.goahead(0)
  File "C:\Program Files\Python39\lib\html\parser.py", line 162, in goahead
    self.handle_data(unescape(rawdata[i:j]))
  File "C:\Users\Castel\AppData\Roaming\Python\Python310\site-packages\fpdf\html.py", line 287, in handle_data
    self.pdf.write(self.h, data)
  File "C:\Users\Castel\AppData\Roaming\Python\Python310\site-packages\fpdf\fpdf.py", line 317, in wrapper
    return fn(self, *args, **kwargs)
  File "C:\Users\Castel\AppData\Roaming\Python\Python310\site-packages\fpdf\fpdf.py", line 3274, in write
    normalized_string = self.normalize_text(txt).replace("\r", "")
  File "C:\Users\Castel\AppData\Roaming\Python\Python310\site-packages\fpdf\fpdf.py", line 3705, in normalize_text
    raise FPDFUnicodeEncodingException(
fpdf.errors.FPDFUnicodeEncodingException: Character "–" at index 76 in text is outside the range of characters supported by the font used: "helveticaI". Please consider using a Unicode font.

image

dict_simboluri = dict()
dict_simboluri['&#259;'] = 'ă'
dict_simboluri['&#226;'] = 'â'
dict_simboluri['&atilde;'] = 'ã'
dict_simboluri['&acirc;'] = 'â'
dict_simboluri['&#x103;'] = 'ă'
dict_simboluri['&#xE2;'] = 'a'

dict_simboluri['  '] = ' '

dict_simboluri['&icirc;'] = 'î'
dict_simboluri['&#206;'] = 'Î'
dict_simboluri['&#238;'] = 'î'
dict_simboluri['&#xEE;'] = 'î'
dict_simboluri['&#xCE;'] = 'Î'
dict_simboluri['&#206;'] = 'Î'
dict_simboluri['&#xEE;'] = 'î'
dict_simboluri['&#xCE;'] = 'i'
dict_simboluri['&Icirc;'] = 'Î'

dict_simboluri['&nbsp;'] = ' '

dict_simboluri['&#537;'] = 'ș'
dict_simboluri['&#536;'] = 'Ș'
dict_simboluri['&#350;'] = 'Ş'
dict_simboluri['&#x219;'] = 'ș'
dict_simboluri['&#351;'] = 's'

dict_simboluri['&amp;'] = ''

dict_simboluri['&#539;'] = 'ț'
dict_simboluri['&#355;'] = 'ț'
dict_simboluri['&#354;'] = 'Ţ'
dict_simboluri['&#x21B;'] = 'ț'
@me-suzy me-suzy added the bug label Aug 26, 2022
@semaeostomea
Copy link

The error message is telling you what's wrong:
fpdf.errors.FPDFUnicodeEncodingException: Character "–" at index 76 in text is outside the range of characters supported by the font used: "helveticaI". Please consider using a Unicode font.

This is not the same character as - (U+2212) , the unicode of this dash is U+2013

The Helvetica font doesn't support this character, so you need to use a different one, as RedShy mentioned in this comment before, because it also does not support the ş character (and many others in your text)

@Lucas-C
Copy link
Member

Lucas-C commented Aug 29, 2022

Closing this @me-suzy as you haven't answered here but based on the exchange in #505 it seems that you solved things out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants