OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Pyfpdf Turkish Character in Python

  • Thread starter Thread starter Ruhi Ulusoy
  • Start date Start date
R

Ruhi Ulusoy

Guest
I want to create a pdf in my Python application using a text that contains Turkish characters, but I get an error. My codes are below. How can I fix this?

Code:
# -*- 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')

I get an 'UnicodeEncodeError: 'latin-1' codec can't encode character '\u0130' in position 60: ordinal not in range(256)' error if I use the codes below

Code:
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')
<p>I want to create a pdf in my Python application using a text that contains Turkish characters, but I get an error. My codes are below. How can I fix this?</p>

<pre><code># -*- 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')
</code></pre>

<p>I get an 'UnicodeEncodeError: 'latin-1' codec can't encode character '\u0130' in position 60: ordinal not in range(256)' error if I use the codes below</p>

<pre><code>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')
</code></pre>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top