日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

用PHP創建PDF中文文檔

瀏覽:105日期:2023-12-25 16:53:02

我使用的是FPDF(www.fpdf.org),下載了fpdf類庫后,還要使用下面的中文類庫才能支持中文,但只能使用一種中文字體(華文仿宋)。為此我煩惱了很長時間,現在終于搞定了,將TrueType字體轉化為pt1字體使用:

下面是在FPDF上找的一個中文類庫:<?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){$i=count($this->fonts)+1;$fontkey=strtolower($family).strtoupper($style);$this->fonts[$fontkey]=array('i'=>$i,'type'=>'Type0','name'=>$name,'up'=>-120,'ut'=>40,'cw'=>$cw,'CMap'=>$CMap,'registry'=>$registry);}

function AddBig5Font($family='Big5'){$cw=$GLOBALS['Big5_widths'];$name='MSungStd-Light-Acro';$CMap='ETenms-B5-H';$registry=array('ordering'=>'CNS1','supplement'=>0);$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 AddGBFont($family='GB'){$cw=$GLOBALS['GB_widths'];$name='STSongStd-Light-Acro';$CMap='GBKp-EUC-H';$registry=array('ordering'=>'GB1','supplement'=>2);$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 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 and $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;$ns=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 breakif($this->ws>0){$this->ws=0;$this->_out('0 Tw');}$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);$i++;$sep=-1;$j=$i;$l=0;$ns=0;$nl++;if($border and $nl==2)$b=$b2;continue;}if(!$ascii){$sep=$i;$ls=$l;}elseif($c==' '){$sep=$i;$ls=$l;$ns++;}$l+=$ascii ? $cw[$c] : 1000;if($l>$wmax){//Automatic line breakif($sep==-1 or $i==$j){if($i==$j)$i+=$ascii ? 1 : 2;if($this->ws>0){$this->ws=0;$this->_out('0 Tw');}$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);}else{if($align=='J'){if($s[$sep]==' ')$ns--;if($s[$i-1]==' '){$ns--;$ls-=$cw[' '];}$this->ws=($ns>0) ? ($wmax-$ls)/1000*$this->FontSize/$ns : 0;$this->_out(sprintf('%.3f Tw',$this->ws*$this->k));}$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;$ns=0;$nl++;if($border and $nl==2)$b=$b2;}else$i+=$ascii ? 1 : 2;}//Last chunkif($this->ws>0){$this->ws=0;$this->_out('0 Tw');}if($border and 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 or $c==' ')$sep=$i;$l+=$ascii ? $cw[$c] : 1000;if($l>$wmax){//Automatic line breakif($sep==-1 or $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 _putfonts(){$nf=$this->n;foreach($this->diffs as $diff){//Encodings$this->_newobj();$this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');$this->_out('endobj');}$mqr=get_magic_quotes_runtime();set_magic_quotes_runtime(0);foreach($this->FontFiles as $file=>$info){//Font file embedding$this->_newobj();$this->FontFiles[$file]['n']=$this->n;if(defined('FPDF_FONTPATH'))$file=FPDF_FONTPATH.$file;$size=filesize($file);if(!$size)$this->Error('Font file not found');$this->_out('<</Length '.$size);if(substr($file,-2)=='.z')$this->_out('/Filter /FlateDecode');$this->_out('/Length1 '.$info['length1']);if(isset($info['length2']))$this->_out('/Length2 '.$info['length2'].' /Length3 0');$this->_out('>>');$f=fopen($file,'rb');$this->_putstream(fread($f,$size));fclose($f);$this->_out('endobj');}set_magic_quotes_runtime($mqr);foreach($this->fonts as $k=>$font){//Font objects$this->_newobj();$this->fonts[$k]['n']=$this->n;$this->_out('<</Type /Font');if($font['type']=='Type0')$this->_putType0($font);else{$name=$font['name'];$this->_out('/BaseFont /'.$name);if($font['type']=='core'){//Standard font$this->_out('/Subtype /Type1');if($name!='Symbol' and $name!='ZapfDingbats')$this->_out('/Encoding /WinAnsiEncoding');}else{//Additional font$this->_out('/Subtype /'.$font['type']);$this->_out('/FirstChar 32');$this->_out('/LastChar 255');$this->_out('/Widths '.($this->n+1).' 0 R');$this->_out('/FontDescriptor '.($this->n+2).' 0 R');if($font['enc']){if(isset($font['diff']))$this->_out('/Encoding '.($nf+$font['diff']).' 0 R');else$this->_out('/Encoding /WinAnsiEncoding');}}$this->_out('>>');$this->_out('endobj');if($font['type']!='core'){//Widths$this->_newobj();$cw=&$font['cw'];$s='[';for($i=32;$i<=255;$i++)$s.=$cw[chr($i)].' ';$this->_out($s.']');$this->_out('endobj');//Descriptor$this->_newobj();$s='<</Type /FontDescriptor /FontName /'.$name;foreach($font['desc'] as $k=>$v)$s.=' /'.$k.' '.$v;$file=$font['file'];if($file)$s.=' /FontFile'.($font['type']=='Type1' ? '' : '2').' '.$this->FontFiles[$file]['n'].' 0 R';$this->_out($s.'>>');$this->_out('endobj');}}}}

function _putType0($font){//Type0$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 (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(); ?>

標簽: PHP
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
亚洲精品一区二区在线看| 日韩中文字幕一区二区高清99| 午夜亚洲福利| 日本不卡的三区四区五区| 日韩精品一区二区三区av | 玖玖玖国产精品| 丝袜美腿成人在线| 青草久久视频| 久久久久久久久成人| 老司机精品视频网| 免费在线小视频| 亚洲深夜影院| 国产日韩一区二区三区在线播放| 老司机免费视频一区二区三区| 久久九九99| 亚洲精品乱码| 成人午夜毛片| 午夜在线精品| 久久av电影| 亚洲国产不卡| 国产精品一区2区3区| 天堂日韩电影| 亚洲精品看片| 捆绑调教日本一区二区三区| 国产精品试看| 国产欧美综合一区二区三区| 日韩在线短视频| 日韩精品成人在线观看| 中文字幕在线看片| 亚洲欧洲专区| 久久久久国产一区二区| 亚洲一区国产一区| 国产精品丝袜xxxxxxx| 国产欧美一区二区精品久久久| 精品三区视频| 美女精品在线| 精品一区二区三区中文字幕| 性欧美69xoxoxoxo| 国产九九精品| 婷婷综合社区| 日韩免费精品| 日韩精品一卡| 久久不卡国产精品一区二区| 1024精品一区二区三区| 日韩和欧美一区二区三区| 免费看av不卡| 日韩精品视频在线看| 欧美freesex黑人又粗又大| 亚洲tv在线| 免费不卡中文字幕在线| 欧美国产专区| 亚洲精品观看| 欧美不卡在线| 精品视频久久| 青青青国产精品| 日韩中文字幕区一区有砖一区| 日韩一级欧洲| 成人一区而且| 国产无遮挡裸体免费久久| 亚洲精品小说| 涩涩av在线| 欧美aa在线视频| 日韩激情一区二区| 夜夜精品视频| 91精品一区二区三区综合| 麻豆精品视频在线| 日韩在线成人| 国产亚洲综合精品| 日韩毛片在线| 韩日一区二区| 亚久久调教视频| av不卡免费看| 欧洲亚洲一区二区三区| 国产一区二区三区国产精品| 日韩精品第二页| 免费人成网站在线观看欧美高清| 精精国产xxxx视频在线野外| 久久中文精品| 久久av偷拍| 欧美成人精品一级| 国产精品3区| 欧美一区91| 欧美一区=区三区| 日韩在线观看中文字幕| 亚洲欧美网站在线观看| 亚洲精品国产偷自在线观看| 日韩一区二区三区免费| 日本а中文在线天堂| 国产精品国产三级国产在线观看| 久久99国产精品视频| 久久成人福利| 精品国产午夜肉伦伦影院 | 亚洲精品在线国产| 免费看黄色91| 亚洲精品动态| 日本91福利区| 国产日本亚洲| 欧美激情三区| 中文在线免费视频| 国产精品成久久久久| 中文字幕在线官网| 久久免费国产| 性欧美精品高清| 亚洲精品字幕| 久久精品国产亚洲夜色av网站| 国产欧美日韩精品一区二区三区| 91精品国产自产精品男人的天堂 | 99精品在线观看| 亚洲v在线看| 日韩一区二区久久| 蜜桃视频一区二区三区| 免费一级片91| 亚洲最新av| 国产亚洲久久| 国产资源在线观看入口av| 99久久九九| 美女久久网站| 欧美日韩亚洲一区二区三区在线| 国产精品美女午夜爽爽| 精品久久97| 精品欧美久久| 日韩激情中文字幕| 国产成人精品免费视| 亚洲无线一线二线三线区别av| 中文日韩在线| 国产毛片一区二区三区 | 麻豆成人综合网| 日韩精品电影| 蜜臀av一区二区在线免费观看| 日韩精品午夜| 日韩不卡一区| 影音国产精品| 国产精品资源| 日韩欧美午夜| 国产精品试看| 国产亚洲欧美日韩在线观看一区二区| 精品福利久久久| 一本一本久久| 久久99高清| 性欧美精品高清| 久久精品福利| 亚洲大全视频| 国产精品对白久久久久粗| 久久免费国产| 国产欧美一级| 日韩一区二区久久| 久久av综合| 日韩午夜av| 欧美国产亚洲精品| 免费视频久久| 亚洲精品**中文毛片| 中文字幕中文字幕精品| 福利片在线一区二区| 日本欧洲一区二区| a日韩av网址| 日韩高清电影一区| 91tv亚洲精品香蕉国产一区| 视频国产精品| 久久在线电影| 免费一级欧美片在线观看网站 | 99热免费精品| 老牛国产精品一区的观看方式| 精品亚洲成人| 午夜在线视频一区二区区别 | 美女少妇全过程你懂的久久| 国产亚洲电影| 视频一区免费在线观看| 高潮久久久久久久久久久久久久| 女主播福利一区| 久久久久久久欧美精品| 日韩视频一区| 欧美日韩视频网站| 久久av中文| 日韩黄色av| 亚洲精选91| 尤物tv在线精品| 国产欧美日韩| 在线亚洲自拍| 91tv亚洲精品香蕉国产一区| 欧美日韩xxxx| 蜜臀av在线播放一区二区三区 | 亚洲精品一级二级三级| 一区二区三区四区在线看| 精品亚洲a∨| 国产精品香蕉| 日本久久二区| 亚洲精品影视| 久久国产精品久久久久久电车| 亚洲精品一区三区三区在线观看| 精品一区二区三区中文字幕| 欧美亚洲人成在线| 亚洲最新av| 免费国产自线拍一欧美视频| 欧美日韩一二| 深夜福利视频一区二区| 国产精品成人**免费视频| 日韩av中文字幕一区| 亚洲精品免费观看| 亚洲影院天堂中文av色| 日韩一区欧美二区|