我想使用包含土耳其语字符的文本在我的 Python 应用程序中创建一个 pdf,但是我收到了一个错误。我的代码如下。我怎样才能解决这个问题?
# -*- coding: utf-8 -*-
from fpdf import FPDF
import os
def add_image(image_path):
pdf = FPDF()
pdf.add_page()
epw = pdf.w - 2 * pdf.l_margin
pdf.set_font('Arial', 'B', 14.0)
txt = u'ATATÜRK LİSESİ 2019 2020 EĞİTİM ÖĞRETİM YILI 11C SINIFI'
stxt = txt.encode('iso-8859-9')
pdf.cell(epw, 0.0, stxt, align='C')
如果我使用下面的代码,我会收到 'UnicodeEncodeError: 'latin-1' codec can't encode character '\u0130' in position 60: ordinal not in range(256)' 错误
epw = pdf.w - 2 * pdf.l_margin
pdf.set_font('Arial', 'B', 14.0)
txt = 'ATATÜRK LİSESİ 2019 2020 EĞİTİM ÖĞRETİM YILI 11C SINIFI'
#stxt = txt.encode('iso-8859-9')
pdf.cell(epw, 0.0, txt, align='C')