Skip to content

BaseMax/mpdf-utf8-php-example

Repository files navigation

mpdf-utf8-php-example

A simple PHP project demonstrating how to generate right-to-left (RTL) Persian invoices as PDFs using mPDF. This setup supports full UTF-8 rendering, RTL text, and is ready to clone, run, and customize.

✨ Key Features

  • Generates Persian-language invoices with correct RTL layout
  • Handles UTF-8 non-ASCII characters
  • Loads and embeds RTL text
  • Supports multiple PHP versions (see compatibility section)

Tested in PHP 8.4 - Ubuntu OS.


⚠️ Challenges Covered

This example solves common issues when working with Persian (Farsi) PDFs in PHP:

  • ✅ Right-to-left text layout
  • ✅ UTF-8 character support (Arabic script, numbers)
  • TODO: Custom TTF font loading and usage in mPDF (Help needed)

ℹ️ The example uses Vazirmatn, a high-quality Persian typeface by the late VazirMatn – a respected contributor to the Persian design community. Best and be at peace.


🧰 PHP Compatibility

Make sure to match your PHP version with the correct mPDF version:

PHP Version Minimum mPDF Version
≥ 5.6 < 7.3 7.0
7.3 7.1.7
7.4 8.0.4
8.0 8.0.10
8.1 8.0.13
8.2 8.1.3
8.3 8.2.1
8.4 8.2.5

Required PHP Extensions

Make sure the following extensions are enabled in your php.ini:

  • mbstring
  • gd

📦 Installation

git clone https://github.com/BaseMax/mpdf-utf8-php-example.git
cd mpdf-utf8-php-example
composer install
php -S localhost:8000

Then open http://localhost:8000/invoice.php in your browser.


📄 License

MIT License

© 2025 Max Base

About

Example repo using mPDF with PHP to render RTL Persian PDF invoices. Ready to clone and run with full UTF-8 and font support.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages