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

PDF metadata doesn't work for Unicode strings #685

Closed
eroux opened this issue Feb 14, 2023 · 5 comments · Fixed by #689
Closed

PDF metadata doesn't work for Unicode strings #685

eroux opened this issue Feb 14, 2023 · 5 comments · Fixed by #689

Comments

@eroux
Copy link

eroux commented Feb 14, 2023

When running the following:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page(format=(200,200))
pdf.set_creator("༄༅། །སྒྲུབ།")
pdf.output("test-tib.pdf")

I get

Traceback (most recent call last):
  File "test-tib-metadata.py", line 6, in <module>
    pdf.output("test-tib.pdf")
  File "/home/eroux/.local/lib/python3.7/site-packages/fpdf/fpdf.py", line 4492, in output
    self.buffer = output_producer.bufferize()
  File "/home/eroux/.local/lib/python3.7/site-packages/fpdf/output.py", line 442, in bufferize
    self._out(pdf_obj.serialize(_security_handler=fpdf._security_handler))
  File "/home/eroux/.local/lib/python3.7/site-packages/fpdf/output.py", line 462, in _out
    data = data.encode("latin1")
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 61-63: ordinal not in range(256)

I notice that the PHP FPDF has an option for UTF8 metadata, perhaps a similar option could be implemented?

@Lucas-C
Copy link
Member

Lucas-C commented Feb 14, 2023

Thank you for the bug report. I am currently working on a fix.

@Lucas-C
Copy link
Member

Lucas-C commented Feb 14, 2023

@allcontributors please add @eroux for bug

@allcontributors
Copy link

@Lucas-C

I've put up a pull request to add @eroux! 🎉

@eroux
Copy link
Author

eroux commented Feb 14, 2023

fantastic, thanks!

@Lucas-C
Copy link
Member

Lucas-C commented Feb 14, 2023

This has not been released in a new version of fpdf2, but you can already test it using the latest, unreleased, development version straight from the development branch of this repository:

pip install git+https://github.com/PyFPDF/fpdf2.git@master

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

Successfully merging a pull request may close this issue.

2 participants