0

I want to write a Farsi text and create its 'PDF' file. I installed and used the fpdf module, but I got an error.

from fpdf import FPDF
def export_pdf():
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Arial", size=15)
    pdf.cell(200, 10, txt='این متن فارسی است.', ln=1, align='R')
    pdf.output('output.pdf')

Error is:

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 51-53: ordinal not in range(256)

Do you have any solution?

My code:

1 Answers1

0

Add #! coding: utf-8 to the beginning of the file.