[英]AttributeError: 'table__n_a_m_e' object has no attribute 'getBestFullName' error on fpdf2
我正在嘗試從 fpdf2 pyfpdf.github.io/fpdf2/Unicode.html運行示例代碼。 它給了我錯誤
回溯(最近調用最后):文件“fpdf2.py”,第 12 行,在 pdf.add_font('DejaVu', fname='DejaVuSansCondensed.ttf') 文件“C:\Program Files\Python36\lib\site-packages \fpdf\fpdf.py", line 1916, in add_font "name": re.sub("[()]", "", font["name"].getBestFullName()), AttributeError: 'table__n_a_m_e' object 有沒有屬性“getBestFullName”
我已經在我的系統上安裝了 DejaVuSansCondensed 字體。 我無法弄清楚它給我的錯誤。 這是代碼。
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
# Add a DejaVu Unicode font (uses UTF-8)
# Supports more than 200 languages. For a coverage status see:
# http://dejavu.svn.sourceforge.net/viewvc/dejavu/trunk/dejavu-fonts/langcover.txt
pdf.add_font('DejaVu', fname='DejaVuSansCondensed.ttf')
pdf.set_font('DejaVu', size=14)
text = u"""
English: Hello World
Greek: Γειά σου κόσμος
Polish: Witaj świecie
Portuguese: Olá mundo
Russian: Здравствуй, Мир
Vietnamese: Xin chào thế giới
Arabic: مرحبا العالم
Hebrew: שלום עולם
"""
for txt in text.split('\n'):
pdf.write(8, txt)
pdf.ln(8)
# Add a Indic Unicode font (uses UTF-8)
# Supports: Bengali, Devanagari, Gujarati,
# Gurmukhi (including the variants for Punjabi)
# Kannada, Malayalam, Oriya, Tamil, Telugu, Tibetan
pdf.add_font('gargi', fname='gargi.ttf')
pdf.set_font('gargi', size=14)
pdf.write(8, u'Hindi: नमस्ते दुनिया')
pdf.ln(20)
# Add a AR PL New Sung Unicode font (uses UTF-8)
# The Open Source Chinese Font (also supports other east Asian languages)
pdf.add_font('fireflysung', fname='fireflysung.ttf')
pdf.set_font('fireflysung', size=14)
pdf.write(8, u'Chinese: 你好世界\n')
pdf.write(8, u'Japanese: こんにちは世界\n')
pdf.ln(10)
# Add a Alee Unicode font (uses UTF-8)
# General purpose Hangul truetype fonts that contain Korean syllable
# and Latin9 (iso8859-15) characters.
pdf.add_font('eunjin', fname='Eunjin.ttf')
pdf.set_font('eunjin', size=14)
pdf.write(8, u'Korean: 안녕하세요')
pdf.ln(20)
# Add a Fonts-TLWG (formerly ThaiFonts-Scalable) (uses UTF-8)
pdf.add_font('waree', fname='Waree.ttf')
pdf.set_font('waree', size=14)
pdf.write(8, u'Thai: สวัสดีชาวโลก')
pdf.ln(20)
# Select a standard font (uses windows-1252)
pdf.set_font('helvetica', size=14)
pdf.ln(10)
pdf.write(5, 'This is standard built-in font')
pdf.output("unicode.pdf")
我剛遇到同樣的問題。 由於這個問題仍然很新,所以這是我為解決它所做的工作:
首先,請注意:該問題似乎是 fpdf2 中的一個已知錯誤,源於從fonttools
fpdf2 v2.5.7
開始引入庫 fonttools。
https://github.com/PyFPDF/fpdf2/issues/524
所以我卸載fonttools
和fpdf2
,然后重新安裝了不同版本的fpdf2
:
pip install fpdf2==2.4.6
現在,AttributeError 消失了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.