电脑软硬件应用网
当前位置: 电脑软硬件应用网 > 设计学院 > 网络编程 > PHP教程 > 正文
用PHP创建PDF中文文档
用PHP创建PDF中文文档
2005-12-30 19:21:12  文/45IT收集   出处:电脑软硬件应用网   
nfo <</Registry (Adobe) /Ordering (''.$font[''registry''][''ordering''].'') /Supplement ''.$font[''registry''][''supplement''].''>>'');
$this->_out(''/FontDescriptor ''.($this->n+1).'' 0 R'');
$W=''/W [1 ['';
foreach($font[''cw''] as $w)
$W.=$w.'' '';
$this->_out($W.'']]'');
$this->_out(''>>'');
$this->_out(''endobj'');
//Font descriptor
$this->_newobj();
$this->_out(''<</Type /FontDescriptor'');
$this->_out(''/FontName /''.$font[''name'']);
$this->_out(''/Flags 6'');
$this->_out(''/FontBBox [0 0 1000 1000]'');
$this->_out(''/ItalicAngle 0'');
$this->_out(''/Ascent 1000'');
$this->_out(''/Descent 0'');
$this->_out(''/CapHeight 1000'');
$this->_out(''/StemV 10'');
$this->_out(''>>'');
$this->_out(''endobj'');
}
}
?>

将以上代码存为chinese.php即可引用。但用它只能得到一种字体。为了支持所有中文字体,可用ttf2pt1程序将TrueType字体转化pt1字体,一个一个地转(具体方法在FPDF的教程中有详细说明)。为了支持其他中文字体,养分要修改上面的chinese.php,如下:

1: Replace the following line in the AddGBFont() method: 

function AddGBFont($family=''GB'',$name=''STSongStd-Light-Acro'') 

$cw=$GLOBALS[''GB_widths'']; 
// $name=''STSongStd-Light-Acro''; 
$CMap=''GBKp-EUC-H''; 
........ 

2: This is a Sample. 

<?php 
require(''chinese.php''); 

$pdf=new PDF_Chinese(); 
$pdf->AddGBFont(''simsun'',''宋体''); 
$pdf->AddGBFont(''simhei'',''黑体''); 
$pdf->AddGBFont(''simkai'',''楷体_GB2312''); 
$pdf->AddGBFont(''sinfang'',''仿宋_GB2312''''); 
$pdf->Open(); 
$pdf->AddPage(); 
$pdf->SetFont(''simsun'','''',20); 
$pdf->Write(10,''简体中文汉字‘); 
$pdf->SetFont(''simhei'','''',20); 
$pdf->Write(10,''简体中文汉字’); 
$pdf->SetFont(''simkai'','''',20); 
$pdf->Write(10,''简体中文汉字‘); 
$pdf->SetFont(''sinfang'','''',20); 
$pdf->Write(10,''简体中文汉字’); 
$pdf->Output(); 
?>

上一页  [1] [2] [3] 

  • 上一篇文章:

  • 下一篇文章:
  • 最新热点 最新推荐 相关文章
    javascript实用技巧点滴(三)
    javascript实用技巧点滴(2)
    javascript实用技巧点滴(1)
    javascript教程 - 第一课 1.1
    用js制作完善的日,月组合下拉框
    利用JSP编程建立动态Web站点
    用PHP制作留言板
    PHP生成动态WAP页面
    PHP实现文件下载
    PHP4的session功能
    关于45IT | About 45IT | 联系方式 | 版权声明 | 网站导航 |

    Copyright © 2003-2011 45IT. All Rights Reserved 浙ICP备09049068号