Haya D
Haya D

Reputation: 407

DOMPDF Doesn't support arabic characters

Can Any one help me please,

I'm using DOMPDF and it's working good but not with the Arabic characters. It shows these (???)

I tried using : <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> in the head tag , also : <style type="text/css"> html,body{ font-family: 'tahoma' ; } </style>

but it's not working. Please help me with this Thanks in Advance :)

Upvotes: 10

Views: 17894

Answers (5)

Abdul Razak Zakieh
Abdul Razak Zakieh

Reputation: 774

Inspired by the answer by @Meldin Xavier, you can put whatever font you'd like for your document and make the font for Arabic parts "DejaVu Sans". I had to use it since I had both Arabic and English and I wanted the English parts to have different font.

Upvotes: 0

Meldin Xavier
Meldin Xavier

Reputation: 317

Use below style in your html

<style> 
 * { font-family: DejaVu Sans, sans-serif; }
</style>

Upvotes: 12

Rahul Kumar Yadav
Rahul Kumar Yadav

Reputation: 19

dompdf/dompdf_config.inc.php

def("DOMPDF_DEFAULT_FONT", "sarif");

Replace:-

def("DOMPDF_DEFAULT_FONT", "dejavu sans");

Upvotes: 1

Mahmoud El Selimy
Mahmoud El Selimy

Reputation: 45

In order to add a font to dompdf you do not need to go through all the steps as described in there wiki. I had the same problem and all I did was download the font .ttf file, then add the following css to my html:

@font-face {
    font-family: Arial;
    src: url(template/fonts/Arial Regular.ttf);
}
body {
    background: #FFF;
    font-family: Arial;
}

Since we've added the font-face in our style, dompdf will grab the ttf file and display the font.


Another method is upload the .ttf and .afm font files (Ex: arial-regular.ttf, arial-regular.afm) to "lib/fonts/" then update the file named "dompdf_font_family_cache.dist.php" in "lib/fonts/" by adding the following code:

'arial' => 
  array (
    'normal' => DOMPDF_FONT_DIR . 'arial-regular',
    'bold' => DOMPDF_FONT_DIR . 'arial-regular',
    'italic' => DOMPDF_FONT_DIR . 'arial-regular',
    'bold_italic' => DOMPDF_FONT_DIR . 'arial-regular',
  ),

This way when you use the arial font on you html page, it will automatically load arial-regular.ttf & arial-regular.afm and display the font correctly.


If you have the .ttf file and not the .afm file you can convert .ttf to .afm using this online tool http://everythingfonts.com/ttf-to-afm

Upvotes: 0

developerwjk
developerwjk

Reputation: 8659

See the quick guide to turning on unicode support for DOMPDF: https://code.google.com/p/dompdf/wiki/CPDFUnicode

For DOMPDF to handle your characters correctly you must enable Unicode support in your configuration. Edit dompdf_config.inc.php or dompdf_config.custom.inc.php so that DOMPDF_UNICODE_ENABLED is true. Without enabling this setting your text will be re-encoded to Windows ANSI when inserted into the PDF and any characters that fall outside this encoding will be converted to question marks.

Upvotes: -1

Related Questions