Repository

mpdf-utf8-php-example

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

PHP Version
Minimum mPDF Version
≥ 5.6 < 7.3
7.0
7.3
7.1.7
7.4
8.0.4

Specs

  • PHP VersionMinimum mPDF Version
  • ≥ 5.6 < 7.37.0
  • 7.37.1.7
  • 7.48.0.4
  • 8.08.0.10
  • 8.18.0.13
  • 8.28.1.3
  • 8.38.2.1
  • 8.48.2.5

README

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

✨ Key Features

1

  • 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)

⚠️ Challenges Covered

2

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

🧰 PHP Compatibility

1

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

Required PHP Extensions

1

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

📦 Installation

1

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

📄 License

1

  • MIT License