I have used DOMPDF library in codeigniter to fetch data from mysql. But there are some fields in my table is in Hindi (unicode form of Hindi) when I am trying to generate PDF fo
In order to correctly render Hindi characters in the PDF you'll need to check a few things:
1. Make sure PHP is using MBString (enabled by default)
2. Make sure you are using Dompdf 0.6.0 or higher
3. Check your settings
If using Dompdf 0.6.x set DOMPDF_ENABLE_UNICODE to true. Dompdf 0.7.0 and higher have this enabled by default.
You will need read/write access to the font directory and font cache directory. By default these directories are under the dompdf directory (dompdf/lib/fonts for both). In Dompdf 0.6.x that would be the DOMPDF_FONT_DIR and DOMPDF_FONT_CACHE configuration constants. In Dompdf 0.7.0 and higher be sure to set the value of the fontDir and fontCache options (e.g. $dompdf->set_option("fontDir", "/my/font/dir");
).
If loading a font via @font-face
make sure you also have read/write access to the temporary directory. In Dompdf 0.6.0 check the DOMPDF_TEMP_DIR configuration constant. In Dompdf 0.7.0 and higher set the tempDir option.
Also, generally speaking, if you're loading any resources via HTTP make sure you have remote resource loading enabled. In Dompdf 0.6.0 check the DOMPDF_ENABLE_REMOTE configuration constant. In Dompdf 0.7.0 and higher set the isRemoteEnabled option.
4. Load a supporting font into Dompdf
Easiest and recommended method for loading a font is using the @font-face
CSS declaration.
By far the easiest way to get started would be to use Google fonts since all you have to do is link to the stylesheet. For the Hind font you would just add the following to your document head:
<link href="https://fonts.googleapis.com/css?family=Hind:400,700&subset=devanagari,latin-ext" rel="stylesheet">
Unfortunately Dompdf does not support numeric weights for fonts. Since this is how Google defines the font weight you can't really use this with Dompdf up to and including 0.8.1. You can hack around the issue, but the easiest method is to download the fonts.
In your document stylesheet:
@font-face {
font-family: Hind;
font-style: normal;
font-weight: normal;
src: url(http://example.com/hind.ttf) format('truetype');
}
Note: Don't forget to define the various weights and styles you want to support.
5. Set the font-family
style attribute for your text to the font you loaded
In your document stylesheet style the relevant container with the appropriate font family. For example, if you want the entire document to use the font you could just add the following to your document stylesheet:
* {
font-family: Hind, DejaVu Sans, sans-serif;
}
This is all covered in the Unicode How-to.
For your issue, mpdf is better than DomPDF and others. it has following features
Add custom fonts
Full Unicode support
It supports more than 100 languages including English, Hindi, Tamil, Sinhala, KATAKANA, HIRAGANA, ETHIOPIC,THAI, MALAYALAM, KANNADA, TELUGU, GUJARATI, BENGALI , ARABIC, GREEK and many more by default
Complex scripts support
3.1 Right-to-left languages
Arabic languages and Hebrew are written in a right-to-left direction (RTL). mPDF recognises both Arabic and Hebrew languages and reverses text direction automatically.
ألسّلام عليكم שלום
3.2 Indic languages, Lao, Tibetan etc
Other complex scripts require some processing of characters before display. For example some vowels consist of 2 characters, to be placed before and after the adjacent consonant e.g.
U+0D1C + U+0D4C [vowel AU] = [written together as ജൌ]
ജ + ൌ = ജൌ
Consonant conjuncts are where two adjacent characters are written as a single ‘conjunct’ form e.g.
प + ॡ = पॣ
3.3 Vertical writing
Vertical writing is not supported by mPDF (e.g. Mongolian and Phags-pa) although the individual characters can be displayed using suitable fonts.