How to make DOMPDF support unicode font step by step?
Solution 1
- Enable the mbstring extension
- Find a font in
.ttf
format with characters that support your given language - Generate a
.afm
file for DOMPDF:- Using the command line,
cd
into the directory which containsload_font.php
, then runphp load_font.php FontName /path/to/font.ttf
- Using the online tool, fill out the form and download the zip it gives you. Copy the files from this zip into
dompdf/lib/fonts
. If you've done this before, add relevant lines todompdf_font_family_cache
, otherwise simply rename thedompdf_font_family_cache.sample
todompdf_font_family_cache
- Using the command line,
-
Enable DOMPDF's Unicode mode, by making sure the line
define("DOMPDF_UNICODE_ENABLED", true);
is set in
dompdf_config.inc.php
. If it readsfalse
instead oftrue
, change that.
Solution 2
There is a wiki page for this.
The next beta (0.6 beta 3), to be released soon, has a font installer that doesn't require the command line (neither any compilation).
You already can use it by checking out the SVN trunk. This beta also supports @font-face
.
Solution 3
As of version 0.7, dompdf supports and has unicode enabled by default. (therefore there is no need for configuration).
Not all dompdf fonts support unicode though. I used font-family: DejaVu Sans
with success.
To install a custom font or learn more about it you can read the official unicode how to.
Solution 4
Download load_font.php and place in ur project root
View load_font.php
add $fontDir = "storage/fonts";
This will show where the fonts are added.
download your font at eg: PREETI and place at your project root
run in command line php load_font.php PREETI PREETI.ttf
then you font will be installed to storage/fonts
directory
now go to the pdf file and add
<style>
body {
font-family: PREETI;
color: #1c2221;
}
</style>
Piseth Sok
I like NodeJS. I like Express. I like ReactJS. I like PHP and MySQL. I like Laravel. I like Arduino Programming.
Updated on June 05, 2022Comments
-
Piseth Sok almost 2 years
I used DOMPDF library and now I have problem with content with unicode language. and I found this one dompdf help but I don't understand about this. can anyone tell the detail of this? thanks
-
Piseth Sok over 12 yearsI got message: Unable to locate the ttf2afm / ttf2pt1 executable (checked /home/piseth/dev/example/pdf_php/lib/ttf2ufm/ttf2ufm-src/ttf2pt1).
-
Piseth Sok over 12 yearsThe SVN trunk not work I have
def("DOMPDF_UNICODE_ENABLED", true);
change this also but still not work. -
Saša Šijak over 12 yearsSounds like you need to install tt2afm or tt2pt1. Try ttf2pt1.sourceforge.net
-
BrianS over 12 years@user970587 it would help to see a sample of the code you're attempting to render (and more detail about what you've tried)
-
deem almost 11 yearsI tried your instruction, but it doesn't work. I read in another topic that I should add css about font family to the print.tpl and it really works then.
-
Mr. Tomar about 8 yearsI followed the above instruction, but not work for me.
-
Mr. Tomar about 8 yearswhen i generate the pdf form html which contain burmese language( நான் என் முதலாளி வீட்டில் ஜன்னல்கள் வெளிப்புறம் சுத்தம் செய்ய தேவையில்லை என்று புரிந்துகொள்ளுங்கள் . ) then in pdf its show ???????????????????????????????????????????????
-
Vinoth Kumar over 2 yearsAny possibilities to display tamil content by using dompdf. I have used dompdf in codeigniter and trying to display tamil content but it showing 1.??? ????? ?????? ??????? any one can help me on this