def dotest(outputname, nostamp): pdf = FPDF() pdf.unifontsubset = False if nostamp: pdf._putinfo = lambda: common.test_putinfo(pdf) pdf.add_page() pdf.set_font('Arial', 'I', 8) # 1. Test: # with txt = txt.encode('latin1') in function normalize_text of module fpdf.py # and using # # txt = all_pdf_chars # # you will get # "UnicodeEncodeError: 'latin-1' codec can't encode character" # for each of the chars in chars_not_in_latin_1 # 2. Test: # with txt = txt.encode('windows-2') in function normalize_text of module fpdf.py # and using # # txt = all_pdf_chars # # you will get # "UnicodeEncodeError: 'windows-1252' codec can't encode character" # for each of the chars in chars_not_in_windows_1252 # 3. Test # with txt = txt.encode('latin1') in function normalize_text of module fpdf.py # and using # # txt = latin_1_chars # # you don't get these errors # 4. Test # with txt = txt.encode('windows-1252') in function normalize_text of module fpdf.py # and using txt = windows_1252_chars # you either don't get these errors # to summarize # all_pdf_chars = windows_1252_chars + chars_not_in_windows_1252 # all_pdf_chars = latin_1_chars + chars_not_in_latin_1 def nrOfChars(var): if var in [all_pdf_chars,windows_1252_chars,latin_1_chars]: return len(var.split('\n'))-2-6 elif var == chars_not_in_windows_1252: return len(var.split('\n'))-2 elif var == chars_not_in_latin_1: return len(var.split('\n'))-2-1 chartexts = {'all':all_pdf_chars, 'windows-1252':windows_1252_chars, 'latin1':latin_1_chars, 'not_in_windows_1252':chars_not_in_windows_1252, 'not_in_latin_1':chars_not_in_latin_1} for k in chartexts.keys(): print(k,nrOfChars(chartexts[k])) # Output: #('all', 229) #('windows-1252', 215) #('latin1', 188) #('not_in_windows_1252', 14) #('not_in_latin_1', 41) # # => not_in_latin_1 - not_in_windows_1252 = 27 pdf.write(8, txt) pdf.output(outputname, 'F')