系统用的是HTML2PDF V4.0.3 版本 百度后 http://blog.sina.com.cn/s/blog_6b0ce0310101fdv6.html 发现中文支持不好 还是有乱码问题 解决办法:
https://github.com/cychai/html2pdf 这是 HTML2PDF V4.0.4版 里面已经介绍很详细 核心问题是由于 字体原因造成 此内容中新增
字体 支持中文部分示例代码:
$html2pdf = new HTML2PDF('P', 'A4', 'en'); $html2pdf->setDefaultFont('javiergb'); $html2pdf->pdf->SetDisplayMode('fullpage'); $html2pdf->writeHTML($content, isset($_GET['vuehtml'])); $html2pdf->Output('exemple_zh_cn.pdf');
字体路径:html2pdf\_tcpdf_5.0.002fonts 放在此目录就好
javiergb.php 代码如下:
/* This font definition is basically stsongstdlight.php The changes I made are commented in place. Javier de Lorenzo-Cáceres 9/SEP/2009 info@civicom.eu Tenerife - Canary Islands - Spain */ $type = 'cidfont0'; // $name = 'STSongStd-Light-Acro'; // TCPDF name doesn't show the apostrophe $name = 'AdobeSongStd-Light'; // name as Reader 8 and 9.1 // $displayname = 'STSong Light (Simp. Chinese)'; $displayname = 'Adobe Song Std L'; // Reader 9.1 $desc = array( 'Ascent' => 752, 'Descent' => -271, 'CapHeight' => 737, 'Flags' => 6, 'FontBBox' => '[-25 -254 1000 880]', 'ItalicAngle' => 0, 'StemV' => 58, 'Style' => '<< /Panose <000000000400000000000000> >>', ); // underline position, needs checking: $up = -130; $ut = 40; $dw=1000; $cw = array( 32 => 207, 33 => 270, 34 => 342, 35 => 467, 36 => 462, 37 => 797, 38 => 710, 39 => 239, 40 => 374, 41 => 374, 42 => 423, 43 => 605, 44 => 238, 45 => 375, 46 => 238, 47 => 334, 48 => 462, 49 => 462, 50 => 462, 51 => 462, 52 => 462, 53 => 462, 54 => 462, 55 => 462, 56 => 462, 57 => 462, 58 => 238, 59 => 238, 60 => 605, 61 => 605, 62 => 605, 63 => 344, 64 => 748, 65 => 684, 66 => 560, 67 => 695, 68 => 739, 69 => 563, 70 => 511, 71 => 729, 72 => 793, 73 => 318, 74 => 312, 75 => 666, 76 => 526, 77 => 896, 78 => 758, 79 => 772, 80 => 544, 81 => 772, 82 => 628, 83 => 465, 84 => 607, 85 => 753, 86 => 711, 87 => 972, 88 => 647, 89 => 620, 90 => 607, 91 => 374, 92 => 333, 93 => 374, 94 => 606, 95 => 500, 96 => 239, 97 => 417, 98 => 503, 99 => 427, 100 => 529, 101 => 415, 102 => 264, 103 => 444, 104 => 518, 105 => 241, 106 => 230, 107 => 495, 108 => 228, 109 => 793, 110 => 527, 111 => 524, 112 => 524, 113 => 504, 114 => 338, 115 => 336, 116 => 277, 117 => 517, 118 => 450, 119 => 652, 120 => 466, 121 => 452, 122 => 407, 123 => 370, 124 => 258, 125 => 370, 126 => 605, ); // CID Information $enc='UniGB-UTF16-H'; $cidinfo=array('Registry'=>'Adobe','Ordering'=>'GB1','Supplement'=> '5');