Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

fpdf is giving UnicodeEncodeError

I am using fpdf python package to create a .pdf file.

This is my code below:

import fpdf
pdf = fpdf.FPDF(format='letter')  # pdf format
pdf.add_page()  # create new page
pdf.set_font("Arial", size=18)  # font and textsize
pdf.cell(200, 10, txt="An enhanced Interactive’ Python", ln=1, align="C")
pdf.output("test.pdf")

But it is giving me an error as:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

UnicodeEncodeError: ‘latin-1’ codec can’t encode character ‘\u2019’ in position 74: ordinal not in range(256)

I am not sure why this is popping up when I want to save the pdf using pdf.output("test.pdf").

>Solution :

U+2019 is the fancy right single quotation mark, which you DO have in your string after the word "Interactive". I suspect you don’t really want that character at all.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading