Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to print Trademark symbol ? #216

Open
shayan-NECX opened this issue Jan 16, 2024 · 2 comments
Open

How to print Trademark symbol ? #216

shayan-NECX opened this issue Jan 16, 2024 · 2 comments

Comments

@shayan-NECX
Copy link

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 ?

@Lucas-C
Copy link

Lucas-C commented Jan 16, 2024

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

@shayan-NECX
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants