pyfpdf
pyfpdf copied to clipboard
How to print Trademark symbol ?
Hi, thanks for the great work on this library. I have to write text to file which contains Trademark symbol. But the library errors out saying:
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2122' in position 0: ordinal not in range(256)
Can you help ? How to print the trademark symbol ?
Hi @shayan-NECX
Note that PyFPDF
is not maintained anymore.
See #207.
fpdf2
is its successor: https://pypi.org/project/fpdf2/
You simply need to use a font that can render this unicode character.
There is some minimal Python code that demonstrate how to do it with fpdf2
:
from fpdf import FPDF
pdf = FPDF()
pdf.set_font("Helvetica", size=24)
pdf.add_page()
pdf.cell(text="©")
pdf.output("issue_216.pdf")
If you need more help, please open an issue on https://github.com/PyFPDF/fpdf2 with some minimal code reproducing your example
Thanks a lot for the quick response Lucas. I basically want this TM sign to display on PDF
from fpdf import FPDF
pdf = FPDF() pdf.set_font("Arial", size=24) pdf.add_page() pdf.cell(0,0,"™") pdf.output("issue_216.pdf")
But i keep getting error:
File "C:\Users\shaya\anaconda3\envs\mymedcard-desktop\lib\site-packages\fpdf\fpdf.py", line 1170, in _putpages p = self.pages[n].encode("latin1") if PY3K else self.pages[n] UnicodeEncodeError: 'latin-1' codec can't encode character '\u2122' in position 50: ordinal not in range(256)
I will create this in fpdf2 .. i guess