I use dompdf to save a html page as pdf by php. I use Persian characters in my html page (actually php page) but when i'm trying to save it as pdf, the export just looked like '?????' :( .I have searched all the net and I found a configuration for unicode characters https://github.com/dompdf/dompdf/wiki/UnicodeHowTo#configure-dompdf-for-unicode-support in "dompdf_config.inc.php" or "dompdf_config.custom.inc.php" file. but the problem is I CAN'T FIND such file in all of my dompdf folder and in all of my file system. Please somebody tell me where it is or what I must do. something else is that I have to use dompdf because of its fantastic CSS compatibility. Thanks.
This is Export.
http://i.stack.imgur.com/nYAzW.png
This is my code.
require("dompdf/autoload.inc.php");
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml("<html><head>
<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">
<link rel=\"stylesheet\" type=\"text/css\" href=\"styles/scorestyle.css\">
</head>
<body><div>
<div id=\"showscorediv\"><table><tbody><tr class=\"scoresubject\"><th colspan=\"2\">کارنامه ارزیابی</th></tr><tr class=\"scorecategory\"><th>شاخص ها</th><th>امیتاز ها</th></tr><tr><td><span class=\"level_0\">شاخص های کیفی</span></td><td class=\"scoretd\">62</td></tr><tr><td><span class=\"level_1\">شاخص های مرتبط با تیم کاری</span></td><td class=\"scoretd\">10</td></tr><tr><td><span class=\"level_1\">شاخص های مرتبط با محصول</span></td><td class=\"scoretd\">28</td></tr><tr><td><span class=\"level_1\">شاخص های مرتبط با بازار</span></td><td class=\"scoretd\">24</td></tr><tr><td><span class=\"level_0\">شاخص های کمی</span></td><td class=\"scoretd\">60</td></tr><tr><td><span class=\"level_1\">شاخص های تولیدی</span></td><td class=\"scoretd\">20</td></tr><tr><td><span class=\"level_1\">شاخص های درآمدی</span></td><td class=\"scoretd\">14</td></tr><tr><td><span class=\"level_1\">شاخص های هزینه ای</span></td><td class=\"scoretd\">26</td></tr><tr class=\"scoresubject\"><th>امتیاز کل</th><th>122</th></tr></tbody></table>
</div>
</div></body></html>");
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream();
You appear to be using dompdf 0.7.0, which no longer uses the dompdf_config.inc.php configuration file. Unicode support is always enabled with this release.
To display the characters used in your sample code you need to ensure that:
$dompdf->set_option('option', 'value');
(where option would be tempDir
, fontDir
, or fontCache
).FYI, you can't just drop the TTF/UFM in your font directory. dompdf has to record information about the font in order to use it. Also, the AFM metrics file won't work in this case anyway because that indicates Windows ANSI encoding on the font. Windows ANSI encoding does not support the characters in your sample. Dompdf uses the UFM metrics format for Unicode support.
The utilities that were included with previous versions of dompdf are no longer included with 0.7.0. So long as you meet the requirements of using the @font-face
declaration you don't need any external utilities. If needed, however, you can find a compatible version of the load_font.php script in the dompdf-utils project.
Since you are using 0.7.0 (which was just released) a lot of info on the Internet may be out of date, so you may want to read up on how to use it:
Lastly, dompdf includes a font (DejaVu) that can support your characters. Try adding the following to your stylesheet so that you have a fallback in case your custom font doesn't work:
* { font-family: BZar_0, DejaVu Sans, sans-serif; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With