Skip to content

Conversation

@otreci4sgelt0nas
Copy link

feat: Add Unicode font detection and enhanced error handling

  • Add UnicodeFontManager class for automatic font detection and recommendations
  • Fix Unicode encoding issues by providing automatic font selection
  • Enable PDF generation with Cyrillic, Arabic, Chinese, and other non-Latin scripts
  • Enhance FPDFUnicodeEncodingException with helpful font suggestions and exact usage instructions
  • Add comprehensive Unicode script detection (Cyrillic, Arabic, Chinese, etc.)
  • Provide system-specific font path detection (macOS, Linux, Windows)
  • Add convenience functions for quick font recommendations
  • Include comprehensive tests and tutorial examples
  • Transform cryptic encoding errors into actionable solutions

This fixes common Unicode encoding issues, especially with Cyrillic characters, by providing automatic font detection and helpful error messages that guide users to appropriate Unicode fonts. Users can now successfully generate PDFs with text in any Unicode script.

- Add UnicodeFontManager class for automatic font detection and recommendations
- Enhance FPDFUnicodeEncodingException with helpful font suggestions
- Add comprehensive Unicode script detection (Cyrillic, Arabic, Chinese, etc.)
- Provide system-specific font path detection (macOS, Linux, Windows)
- Add convenience functions for quick font recommendations
- Include comprehensive tests and tutorial examples
- Improve error messages with specific font recommendations and usage instructions

This addresses common Unicode encoding issues, especially with Cyrillic characters,
by providing automatic font detection and helpful error messages that guide users
to appropriate Unicode fonts.
@andersonhc
Copy link
Collaborator

Hi @otreci4sgelt0nas — thanks for this PR!

At first glance the code looks really solid, and turning cryptic encoding errors into actionable messages sounds really good. The tutorials are helpful too.

A couple of quick notes/questions:

  • It would be great to add a short section to docs/Text.md pointing to the new tutorials and explaining the basic “why/when/how” the user will see those messages.

  • Re: suggestions: are all recommended fonts open/free and clearly licensed? Font licensing can be tricky.

I have limited time this weekend, but I can take a deeper look early next week (unless @Lucas-C beats me to it). Thanks again for the thoughtful contribution!

@Lucas-C
Copy link
Member

Lucas-C commented Sep 8, 2025

I fully agree with @andersonhc feedbacks.
I would also have suggested adding details to the Markdown files in the docs/ folder regarding this, and the licensing is also very relevant 👍

Moreover, the GitHub Actions CI pipeline is failing du to the black code formatter.
You just need to run: black fpdf/ test/fonts/test_unicode_font_utils.py tutorial/unicode_font_detection.py

Copy link
Collaborator

@andersonhc andersonhc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your contribution.

Please:

  • Add a CHANGELOG entry
  • Format the code with black and check with pylint to pass the lint steps
  • Fix the 4 tests failing due to incorrect error assert.

@Lucas-C
Copy link
Member

Lucas-C commented Oct 27, 2025

Hi @otreci4sgelt0nas 🙂 👋
We are close to the end of the month, I was just curious to know if you were willing to finish this PR as part of Hacktoberfest?

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

Successfully merging this pull request may close these issues.

3 participants