问题
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();
回答1:
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:
- You are supplying a font that supports these characters (that appears to be the case).
- That dompdf has both read and write capability to the temporary directory, font directory, and font cache directory. You can set these using
$dompdf->set_option('option', 'value');
(where option would betempDir
,fontDir
, orfontCache
). - The font is accessible to dompdf and is in TTF format.
- You are correctly styling your content to use your font. Hard to know without seeing your CSS.
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:
- dompdf README
- dompdf 0.7.0 release notes
- dompdf wiki (pay attention to any versioning information)
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; }
回答2:
To set any DOMPDF option you have to define a named constant. All available options can be found here: http://pxd.me/dompdf/www/setup.php
To enable Persian characters you basically have to enable unicode support.
define("DOMPDF_UNICODE_ENABLED", true);
You may want to set DOMPDF_FONT_DIR
and DOMPDF_DEFAULT_FONT
as well, just to make sure that the font you're using supports unicode characters.
回答3:
I just added dompdf_config.inc.php and dompdf_config.custom.inc.php files from dompdf 0.6.2 version, besides include dir with autoload.inc.php and functions.inc.php to my dompdf 0.8.* and it works.
来源:https://stackoverflow.com/questions/37182619/i-cant-find-dompdf-config-inc-php-or-dompdf-config-custom-inc-php-for-setting