<?phprequire('chinese.php');$pdf = new PDF_Chinese();$pdf->AddBig5Font();$pdf->AddPage();$pdf->SetFont('Big5', '', 20);$pdf->Write(10, '测试测试');$pdf->Output();?><?phprequire('fpdf.php');$Big5_widths = array(' ' => 250, '!' => 250, '"' => 408, '#' => 668, '$' => 490, '%' => 875, '&' => 698, '\'' => 250,'(' => 240, ')' => 240, '*' => 417, '+' => 667, ',' => 250, '-' => 313, '.' => 250, '/' => 520, '0' => 500, '1' => 500,'2' => 500, '3' => 500, '4' => 500, '5' => 500, '6' => 500, '7' => 500, '8' => 500, '9' => 500, ':' => 250, ';' => 250,'<' => 667, '=' => 667, '>' => 667, '?' => 396, '@' => 921, 'A' => 677, 'B' => 615, 'C' => 719, 'D' => 760, 'E' => 625,'F' => 552, 'G' => 771, 'H' => 802, 'I' => 354, 'J' => 354, 'K' => 781, 'L' => 604, 'M' => 927, 'N' => 750, 'O' => 823,'P' => 563, 'Q' => 823, 'R' => 729, 'S' => 542, 'T' => 698, 'U' => 771, 'V' => 729, 'W' => 948, 'X' => 771, 'Y' => 677,'Z' => 635, '[' => 344, '\\' => 520, ']' => 344, '^' => 469, '_' => 500, '`' => 250, 'a' => 469, 'b' => 521, 'c' => 427,'d' => 521, 'e' => 438, 'f' => 271, 'g' => 469, 'h' => 531, 'i' => 250, 'j' => 250, 'k' => 458, 'l' => 240, 'm' => 802,'n' => 531, 'o' => 500, 'p' => 521, 'q' => 521, 'r' => 365, 's' => 333, 't' => 292, 'u' => 521, 'v' => 458, 'w' => 677,'x' => 479, 'y' => 458, 'z' => 427, '{' => 480, '|' => 496, '}' => 480, '~' => 667);$GB_widths = array(' ' => 207, '!' => 270, '"' => 342, '#' => 467, '$' => 462, '%' => 797, '&' => 710, '\'' => 239,'(' => 374, ')' => 374, '*' => 423, '+' => 605, ',' => 238, '-' => 375, '.' => 238, '/' => 334, '0' => 462, '1' => 462,'2' => 462, '3' => 462, '4' => 462, '5' => 462, '6' => 462, '7' => 462, '8' => 462, '9' => 462, ':' => 238, ';' => 238,'<' => 605, '=' => 605, '>' => 605, '?' => 344, '@' => 748, 'A' => 684, 'B' => 560, 'C' => 695, 'D' => 739, 'E' => 563,'F' => 511, 'G' => 729, 'H' => 793, 'I' => 318, 'J' => 312, 'K' => 666, 'L' => 526, 'M' => 896, 'N' => 758, 'O' => 772,'P' => 544, 'Q' => 772, 'R' => 628, 'S' => 465, 'T' => 607, 'U' => 753, 'V' => 711, 'W' => 972, 'X' => 647, 'Y' => 620,'Z' => 607, '[' => 374, '\\' => 333, ']' => 374, '^' => 606, '_' => 500, '`' => 239, 'a' => 417, 'b' => 503, 'c' => 427,'d' => 529, 'e' => 415, 'f' => 264, 'g' => 444, 'h' => 518, 'i' => 241, 'j' => 230, 'k' => 495, 'l' => 228, 'm' => 793,'n' => 527, 'o' => 524, 'p' => 524, 'q' => 504, 'r' => 338, 's' => 336, 't' => 277, 'u' => 517, 'v' => 450, 'w' => 652,'x' => 466, 'y' => 452, 'z' => 407, '{' => 370, '|' => 258, '}' => 370, '~' => 605);class PDF_Chinese extends FPDF{function AddCIDFont($family, $style, $name, $cw, $CMap, $registry){$fontkey = strtolower($family) . strtoupper($style);if (isset($this->fonts[$fontkey]))$this->Error("Font already added: $family $style");$i = count($this->fonts) + 1;$name = str_replace(' ', '', $name);$this->fonts[$fontkey] = array('i' => $i, 'type' => 'Type0', 'name' => $name, 'up' => -130, 'ut' => 40, 'cw' => $cw, 'CMap' =>$CMap, 'registry' => $registry);}function AddCIDFonts($family, $name, $cw, $CMap, $registry){$this->AddCIDFont($family, '', $name, $cw, $CMap, $registry);$this->AddCIDFont($family, 'B', $name . ',Bold', $cw, $CMap, $registry);$this->AddCIDFont($family, 'I', $name . ',Italic', $cw, $CMap, $registry);$this->AddCIDFont($family, 'BI', $name . ',BoldItalic', $cw, $CMap, $registry);}function AddBig5Font($family = 'Big5', $name = 'MSungStd-Light-Acro'){// Add Big5 font with proportional Latin$cw = $GLOBALS['Big5_widths'];$CMap = 'ETenms-B5-H';$registry = array('ordering' => 'CNS1', 'supplement' => 0);$this->AddCIDFonts($family, $name, $cw, $CMap, $registry);}function AddBig5hwFont($family = 'Big5-hw', $name = 'MSungStd-Light-Acro'){// Add Big5 font with half-witdh Latinfor ($i = 32; $i <= 126; $i++)$cw[chr($i)] = 500;$CMap = 'ETen-B5-H';$registry = array('ordering' => 'CNS1', 'supplement' => 0);$this->AddCIDFonts($family, $name, $cw, $CMap, $registry);}function AddGBFont($family = 'GB', $name = 'STSongStd-Light-Acro'){// Add GB font with proportional Latin$cw = $GLOBALS['GB_widths'];$CMap = 'GBKp-EUC-H';$registry = array('ordering' => 'GB1', 'supplement' => 2);$this->AddCIDFonts($family, $name, $cw, $CMap, $registry);}function AddGBhwFont($family = 'GB-hw', $name = 'STSongStd-Light-Acro'){// Add GB font with half-width Latinfor ($i = 32; $i <= 126; $i++)$cw[chr($i)] = 500;$CMap = 'GBK-EUC-H';$registry = array('ordering' => 'GB1', 'supplement' => 2);$this->AddCIDFonts($family, $name, $cw, $CMap, $registry);}function GetStringWidth($s){if ($this->CurrentFont['type'] == 'Type0')return $this->GetMBStringWidth($s);elsereturn parent::GetStringWidth($s);}function GetMBStringWidth($s){// Multi-byte version of GetStringWidth()$l = 0;$cw = &$this->CurrentFont['cw'];$nb = strlen($s);$i = 0;while ($i < $nb) {$c = $s[$i];if (ord($c) < 128) {$l += $cw[$c];$i++;} else {$l += 1000;$i += 2;}}return $l * $this->FontSize / 1000;}function MultiCell($w, $h, $txt, $border = 0, $align = 'L', $fill = 0){if ($this->CurrentFont['type'] == 'Type0')$this->MBMultiCell($w, $h, $txt, $border, $align, $fill);elseparent::MultiCell($w, $h, $txt, $border, $align, $fill);}function MBMultiCell($w, $h, $txt, $border = 0, $align = 'L', $fill = 0){// Multi-byte version of MultiCell()$cw = &$this->CurrentFont['cw'];if ($w == 0)$w = $this->w - $this->rMargin - $this->x;$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;$s = str_replace("\r", '', $txt);$nb = strlen($s);if ($nb > 0 && $s[$nb - 1] == "\n")$nb--;$b = 0;if ($border) {if ($border == 1) {$border = 'LTRB';$b = 'LRT';$b2 = 'LR';} else {$b2 = '';if (is_int(strpos($border, 'L')))$b2 .= 'L';if (is_int(strpos($border, 'R')))$b2 .= 'R';$b = is_int(strpos($border, 'T')) ? $b2 . 'T' : $b2;}}$sep = -1;$i = 0;$j = 0;$l = 0;$nl = 1;while ($i < $nb) {// Get next character$c = $s[$i];// Check if ASCII or MB$ascii = (ord($c) < 128);if ($c == "\n") {// Explicit line break$this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill);$i++;$sep = -1;$j = $i;$l = 0;$nl++;if ($border && $nl == 2)$b = $b2;continue;}if (!$ascii) {$sep = $i;$ls = $l;} elseif ($c == ' ') {$sep = $i;$ls = $l;}$l += $ascii ? $cw[$c] : 1000;if ($l > $wmax) {// Automatic line breakif ($sep == -1 || $i == $j) {if ($i == $j)$i += $ascii ? 1 : 2;$this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill);} else {$this->Cell($w, $h, substr($s, $j, $sep - $j), $b, 2, $align, $fill);$i = ($s[$sep] == ' ') ? $sep + 1 : $sep;}$sep = -1;$j = $i;$l = 0;$nl++;if ($border && $nl == 2)$b = $b2;} else$i += $ascii ? 1 : 2;}// Last chunkif ($border && is_int(strpos($border, 'B')))$b .= 'B';$this->Cell($w, $h, substr($s, $j, $i - $j), $b, 2, $align, $fill);$this->x = $this->lMargin;}function Write($h, $txt, $link = ''){if ($this->CurrentFont['type'] == 'Type0')$this->MBWrite($h, $txt, $link);elseparent::Write($h, $txt, $link);}function MBWrite($h, $txt, $link){// Multi-byte version of Write()$cw = &$this->CurrentFont['cw'];$w = $this->w - $this->rMargin - $this->x;$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;$s = str_replace("\r", '', $txt);$nb = strlen($s);$sep = -1;$i = 0;$j = 0;$l = 0;$nl = 1;while ($i < $nb) {// Get next character$c = $s[$i];// Check if ASCII or MB$ascii = (ord($c) < 128);if ($c == "\n") {// Explicit line break$this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link);$i++;$sep = -1;$j = $i;$l = 0;if ($nl == 1) {$this->x = $this->lMargin;$w = $this->w - $this->rMargin - $this->x;$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;}$nl++;continue;}if (!$ascii || $c == ' ')$sep = $i;$l += $ascii ? $cw[$c] : 1000;if ($l > $wmax) {// Automatic line breakif ($sep == -1 || $i == $j) {if ($this->x > $this->lMargin) {// Move to next line$this->x = $this->lMargin;$this->y += $h;$w = $this->w - $this->rMargin - $this->x;$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;$i++;$nl++;continue;}if ($i == $j)$i += $ascii ? 1 : 2;$this->Cell($w, $h, substr($s, $j, $i - $j), 0, 2, '', 0, $link);} else {$this->Cell($w, $h, substr($s, $j, $sep - $j), 0, 2, '', 0, $link);$i = ($s[$sep] == ' ') ? $sep + 1 : $sep;}$sep = -1;$j = $i;$l = 0;if ($nl == 1) {$this->x = $this->lMargin;$w = $this->w - $this->rMargin - $this->x;$wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize;}$nl++;} else$i += $ascii ? 1 : 2;}// Last chunkif ($i != $j)$this->Cell($l / 1000 * $this->FontSize, $h, substr($s, $j, $i - $j), 0, 0, '', 0, $link);}function _putType0($font){// Type0$this->_newobj();$this->_out('<</Type /Font');$this->_out('/Subtype /Type0');$this->_out('/BaseFont /' . $font['name'] . '-' . $font['CMap']);$this->_out('/Encoding /' . $font['CMap']);$this->_out('/DescendantFonts [' . ($this->n + 1) . ' 0 R]');$this->_out('>>');$this->_out('endobj');// CIDFont$this->_newobj();$this->_out('<</Type /Font');$this->_out('/Subtype /CIDFontType0');$this->_out('/BaseFont /' . $font['name']);$this->_out('/CIDSystemInfo <</Registry ' . $this->_textstring('Adobe') . ' /Ordering ' . $this->_textstring($font['registry']['ordering']) . ' /Supplement ' . $font['registry']['supplement'] . '>>');$this->_out('/FontDescriptor ' . ($this->n + 1) . ' 0 R');if ($font['CMap'] == 'ETen-B5-H')$W = '13648 13742 500';elseif ($font['CMap'] == 'GBK-EUC-H')$W = '814 907 500 7716 [500]';else$W = '1 [' . implode(' ', $font['cw']) . ']';$this->_out('/W [' . $W . ']>>');$this->_out('endobj');// Font descriptor$this->_newobj();$this->_out('<</Type /FontDescriptor');$this->_out('/FontName /' . $font['name']);$this->_out('/Flags 6');$this->_out('/FontBBox [0 -200 1000 900]');$this->_out('/ItalicAngle 0');$this->_out('/Ascent 800');$this->_out('/Descent -200');$this->_out('/CapHeight 800');$this->_out('/StemV 50');$this->_out('>>');$this->_out('endobj');}}?>

PHP使用fpdf生成pdf文件(含中文类)相关推荐

  1. python使用fpdf生成pdf文件章节(chapter),包含:页眉、页脚、章节主题、数据排版等;

    python使用fpdf生成pdf文件章节(chapter),包含:页眉.页脚.章节主题.数据排版等: #仿真数据 The year 1866 was marked by a bizarre deve ...

  2. python使用fpdf生成pdf文件:配置多种语言字体写入多种文字

    python使用fpdf生成pdf文件:配置多种语言字体写入多种文字 目录

  3. python使用fpdf生成pdf文件并添加页眉和页脚

    python使用fpdf生成pdf文件并添加页眉和页脚 目录 python使用fpdf生成pdf文件并添加页眉和页脚 #加入页眉header示例

  4. python使用fpdf创建pdf文件包含:页眉、页脚并嵌入logo图片、设置使用中文字体

    python使用fpdf创建pdf文件包含:页眉.页脚并嵌入logo图片.设置使用中文字体 #python使用fpdf创建页眉.页脚并嵌入logo图片.设置使用中文字体 from fpdf impor ...

  5. python使用fpdf生成pdf章节(chapter)文件包含:页眉、页脚、章节主体、章节内容等;

    python使用fpdf生成pdf章节(chapter)文件包含:页眉.页脚.章节主体.章节内容等: 目录

  6. 安装texlive并用latex编写一段中文,最后生成pdf文件

    安装texlive并用latex编写一段中文,最后生成pdf文件 **#一.下载安装(**链接https://tug.org/texlive/) ##1.第一步 ##2.第二步 ##3.第三步 ##4 ...

  7. Itext生成pdf文件,itext+Freemarker生成pdf,(中文空白解决)

    来源:https://my.oschina.net/lujianing/blog/894365 1.背景 在某些业务场景中,需要提供相关的电子凭证,比如网银/支付宝中转账的电子回单,签约的电子合同等. ...

  8. java生成pdf字体居中,Java生成pdf文件,解决中文乱码问题

    如下代码使用itext生成pdf文件,通过设置中文字体避免乱码. /** * AsianTest.java */ import java.io.FileOutputStream; import jav ...

  9. PHP生成PDF完美支持中文,解决TCPDF乱码

    PHP生成PDF完美支持中文,解决TCPDF乱码 2011-09-26 09:04 418人阅读 评论(0) 收藏 举报 phpfontsheaderttfxhtml文档 PHP生成PDF完美支持中文 ...

最新文章

  1. 如何在10亿个整数中找出前1000个最大的数(TopN算法)
  2. RobotFramework读取mysql和oracle数据库
  3. HTML 5 Web Socket:下一次Web通信革命揭幕,互联网营销
  4. 从金蝶k3到金税盘_经典全套金蝶K3操作流程大全
  5. 1.10-linux三剑客之sed命令详解及用法
  6. 进程 线程 多进程 多线程 父进程 子进程
  7. Zabbix分布式监控(zabbix-proxy)的配置关键点
  8. xposed hook 静态函数_Xposed 实现原理分析
  9. this指针常识性问题
  10. 【转】机器学习入门——浅谈神经网络
  11. ssh远程连接阿里云服务器
  12. mysql 1031_MySQL5.6数据导入MySQL5.7报错:ERROR 1031 (HY000)
  13. 如何让别人看不懂java代码_为什么你写的代码别人看不懂?
  14. 可视化布局html5
  15. element的上传如何获取路径_element Ui 上传组件upload提交的文件目录 集成进度条样式...
  16. 实验一计算机网络基础知识,计算机网络实验基础知识 集线器的使用
  17. 问题描述:the jar file jrt-fs.jar has no source attachment
  18. Android WebRtc 桌面投屏、视频源码
  19. puppy linux安装到u盘分区,puppy linux如何安装?puppy linux安装到u盘方法
  20. 中国联通广州软件研究院 软件开发岗一面(人力面)

热门文章

  1. 表的插入、更新、删除、合并操作_3_插入新的多条记录
  2. 【Keil C51】使用 watch1 来查看变量的值
  3. defparam的语法
  4. tf.pad函数功能介绍
  5. OpenCV数据类型转换:cnvertTo函数的使用
  6. python将字典写入json文件中
  7. int main(argc,*argv)中argc,argv的相关说明
  8. JDK中的Atomic包中的类及使用
  9. ML之监督学习算法之分类算法一 ——— 决策树算法
  10. AdaBoost 和 Real Adaboost 总结