用PHP创建PDF中文文档

我使用的是FPDF。为此我烦恼了很长时间,现在终于搞定了,将TrueType字体转化为pt1字体使用:

我使用的是FPDF,下载了fpdf类库后,还要使用下面的中文类库才能支持中文,但只能使用一种中文字体。为此我烦恼了很长时间,现在终于搞定了,将TrueType字体转化为pt1字体使用:

<?
//php教程生成pdf文件代码
/*
生成pdf文件如果真的生成很好,是很复杂的,下面我们来看看一款完整理的php生成pdf文件代码吧,他可以把文本文件生成pdf文件也可以利用图片文件生成pdf文件哦。

下面是在FPDF上找的一个中文类库:?phprequire(‘fpdf.php’);

下面是在FPDF上找的一个中文类库:

这款生成pdf文件用到文件有
fpdf.php
chinese.php
picpdf.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);

$Big5_widths=array(‘
‘=>250,’!’=>250,'”‘=>408,’#’=>668,’$’=>490,’%’=>875,’&’=>698,”’=>250,”=>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);

*/
//fpdf.php代码

$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);

$GB_widths=array(‘
‘=>207,’!’=>270,'”‘=>342,’#’=>467,’$’=>462,’%’=>797,’&’=>710,”’=>239,”=>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);

define(‘fpdf_version’,’1.6′);

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);}

class PDF_Chinese extends FPDF{function
AddCIDFont($family,$style,$name,$cw,$CMap,$registry){$i=count+1;$fontkey=strtolower.strtoupper;$this->fonts[$fontkey]=array(‘i’=>$i,’type’=>’Type0’,’name’=>$name,’up’=>-120,’ut’=>40,’cw’=>$cw,’CMap’=>$CMap,’registry’=>$registry);}

class fpdf
{
var $page;               //current page number
var $n;                  //current object number
var $offsets;            //array of object offsets
var $buffer;             //buffer holding in-memory pdf
var $pages;              //array containing pages
var $state;              //current document state
var $compress;           //compression flag
var $k;                  //scale factor (number of points in user
unit)
var $deforientation;     //default orientation
var $curorientation;     //current orientation
var $pageformats;        //available page formats
var $defpageformat;      //default page format
var $curpageformat;      //current page format
var $pagesizes;          //array storing non-default page sizes
var $wpt,$hpt;           //dimensions of current page in points
var $w,$h;               //dimensions of current page in user unit
var $lmargin;            //left margin
var $tmargin;            //top margin
var $rmargin;            //right margin
var $bmargin;            //page break margin
var $cmargin;            //cell margin
var $x,$y;               //current position in user unit
var $lasth;              //height of last printed cell
var $linewidth;          //line width in user unit
var $corefonts;          //array of standard font names
var $fonts;              //array of used fonts
var $fontfiles;          //array of font files
var $diffs;              //array of encoding differences
var $fontfamily;         //current font family
var $fontstyle;          //current font style
var $underline;          //underlining flag
var $currentfont;        //current font info
var $fontsizept;         //current font size in points
var $fontsize;           //current font size in user unit
var $drawcolor;          //commands for drawing color
var $fillcolor;          //commands for filling color
var $textcolor;          //commands for text color
var $colorflag;          //indicates whether fill and text colors are
different
var $ws;                 //word spacing
var $images;             //array of used images
var $pagelinks;          //array of links in pages
var $links;              //array of internal links
var $autopagebreak;      //automatic page breaking
var $pagebreaktrigger;   //threshold used to trigger page breaks
var $inheader;           //flag set when processing header
var $infooter;           //flag set when processing footer
var $zoommode;           //zoom display mode
var $layoutmode;         //layout display mode
var $title;              //title
var $subject;            //subject
var $author;             //author
var $keywords;           //keywords
var $creator;            //creator
var $aliasnbpages;       //alias for total number of pages
var $pdfversion;         //pdf version number

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
AddBig5Font{$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);}

/*******************************************************************************
*                                                                             
*
*                               public
methods                                 *
*                                                                             
*
*******************************************************************************/
function fpdf($orientation=’p’, $unit=’mm’, $format=’a4′)
{
 //some checks
 $this->_dochecks();
 //initialization of properties
 $this->page=0;
 $this->n=2;
 $this->buffer=”;
 $this->pages=array();
 $this->pagesizes=array();
 $this->state=0;
 $this->fonts=array();
 $this->fontfiles=array();
 $this->diffs=array();
 $this->images=array();
 $this->links=array();
 $this->inheader=false;
 $this->infooter=false;
 $this->lasth=0;
 $this->fontfamily=”;
 $this->fontstyle=”;
 $this->fontsizept=12;
 $this->underline=false;
 $this->drawcolor=’0 g’;
 $this->fillcolor=’0 g’;
 $this->textcolor=’0 g’;
 $this->colorflag=false;
 $this->ws=0;
 //standard fonts
 $this->corefonts=array(‘courier’=>’courier’,
‘courierb’=>’courier-bold’, ‘courieri’=>’courier-oblique’,
‘courierbi’=>’courier-boldoblique’,
  ‘helvetica’=>’helvetica’, ‘helveticab’=>’helvetica-bold’,
‘helveticai’=>’helvetica-oblique’,
‘helveticabi’=>’helvetica-boldoblique’,
  ‘times’=>’times-roman’, ‘timesb’=>’times-bold’,
‘timesi’=>’times-italic’, ‘timesbi’=>’times-bolditalic’,
  ‘symbol’=>’symbol’, ‘zapfdingbats’=>’zapfdingbats’);
 //scale factor
 if($unit==’pt’)

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
AddGBFont{$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
GetStringWidth{if($this->CurrentFont[‘type’]==’Type0′)return
$this->GetMBStringWidth;elsereturn parent::GetStringWidth;}

  $this->k=1;
 elseif($unit==’mm’)
  $this->k=72/25.4;
 elseif($unit==’cm’)
  $this->k=72/2.54;
 elseif($unit==’in’)
  $this->k=72;
 else
  $this->error(‘incorrect unit: ‘.$unit);
 //page format
 $this->pageformats=array(‘a3’=>array(841.89,1190.55),
‘a4’=>array(595.28,841.89), ‘a5’=>array(420.94,595.28),
  ‘letter’=>array(612,792), ‘legal’=>array(612,1008));
 if(is_string($format))
  $format=$this->_getpageformat($format);
 $this->defpageformat=$format;
 $this->curpageformat=$format;
 //page orientation
 $orientation=strtolower($orientation);
 if($orientation==’p’ || $orientation==’portrait’)
 {
  $this->deforientation=’p’;
  $this->w=$this->defpageformat[0];
  $this->h=$this->defpageformat[1];
 }
 elseif($orientation==’l’ || $orientation==’landscape’)
 {
  $this->deforientation=’l’;
  $this->w=$this->defpageformat[1];
  $this->h=$this->defpageformat[0];
 }
 else
  $this->error(‘incorrect orientation: ‘.$orientation);
 $this->curorientation=$this->deforientation;
 $this->wpt=$this->w*$this->k;
 $this->hpt=$this->h*$this->k;
 //page margins (1 cm)
 $margin=28.35/$this->k;
 $this->setmargins($margin,$margin);
 //interior cell margin (1 mm)
 $this->cmargin=$margin/10;
 //line width (0.2 mm)
 $this->linewidth=.567/$this->k;
 //automatic page break
 $this->setautopagebreak(true,2*$margin);
 //full width display mode
 $this->setdisplaymode(‘fullwidth’);
 //enable compression
 $this->setcompression(true);
 //set default pdf version number
 $this->pdfversion=’1.3′;
}

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 GetMBStringWidth{//Multi-byte version of
GetStringWidth()$l=0;$cw=&$this->CurrentFont[‘cw’];$nb=strlen;$i=0;while{$c=$s[$i];if{$l+=$cw[$c];$i++;}else{$l+=1000;$i+=2;}}return
$l*$this->FontSize/1000;}

function setmargins($left, $top, $right=null)
{
 //set left, top and right margins
 $this->lmargin=$left;
 $this->tmargin=$top;
 if($right===null)
  $right=$left;
 $this->rmargin=$right;
}

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
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 setleftmargin($margin)
{
 //set left margin
 $this->lmargin=$margin;
 if($this->page>0 && $this->x<$margin)
  $this->x=$margin;
}

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($nb0
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-ws0){$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-ws0){$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=($ns0) ?
($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-ws0){$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
MBMultiCell($w,$h,$txt,$border=0,$align=’L’,$fill=0){//Multi-byte
version of
MultiCell()$cw=&$this->CurrentFont[‘cw’];if$w=$this->w-$this->rMargin-$this->x;$wmax=*1000/$this->FontSize;$s=str_replace;$nb=strlen;if($nb>0
and
$s[$nb-1]==”n”$nb–;$b=0;if{if{$border=’LTRB’;$b=’LRT’;$b2=’LR’;}else{$b2=”;if(is_int$b2.=’L’;if(is_int$b2.=’R’;$b=is_int
? $b2.’T’ : $b2;}}$sep=-1;$i=0;$j=0;$l=0;$ns=0;$nl=1;while{//Get next
character$c=$s[$i];//Check if ASCII or
MB$ascii=;if($c==”n”{//Explicit line
breakif{$this->ws=0;$this->_out;}$this->Cell($w,$h,substr,$b,2,$align,$fill);$i++;$sep=-1;$j=$i;$l=0;$ns=0;$nl++;if$b=$b2;continue;}if{$sep=$i;$ls=$l;}elseif{$sep=$i;$ls=$l;$ns++;}$l+=$ascii
? $cw[$c] : 1000;if{//Automatic line breakif{if$i+=$ascii ? 1 :
2;if{$this->ws=0;$this->_out;}$this->Cell($w,$h,substr,$b,2,$align,$fill);}else{if{if$ns–;if{$ns–;$ls-=$cw[‘
‘];}$this->ws=/1000*$this->FontSize/$ns :
0;$this->_out(sprintf(‘%.3f
Tw’,$this->ws*$this->k));}$this->Cell($w,$h,substr,$b,2,$align,$fill);$i=
? $sep+1 : $sep;}$sep=-1;$j=$i;$l=0;$ns=0;$nl++;if$b=$b2;}else$i+=$ascii
? 1 : 2;}//Last chunkif{$this->ws=0;$this->_out;}if($border and
is_int$b.=’B’;$this->Cell($w,$h,substr,$b,2,$align,$fill);$this->x=$this->lMargin;}

function settopmargin($margin)
{
 //set top margin
 $this->tmargin=$margin;
}

function
Write($h,$txt,$link=”){if($this-CurrentFont[‘type’]==’Type0′)$this-MBWrite($h,$txt,$link);elseparent::Write($h,$txt,$link);}

function
Write{if($this->CurrentFont[‘type’]==’Type0′)$this->MBWrite;elseparent::Write;}

function setrightmargin($margin)
{
 //set right margin
 $this->rmargin=$margin;
}

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 MBWrite{//Multi-byte version of
Write()$cw=&$this->CurrentFont[‘cw’];$w=$this->w-$this->rMargin-$this->x;$wmax=*1000/$this->FontSize;$s=str_replace;$nb=strlen;$sep=-1;$i=0;$j=0;$l=0;$nl=1;while{//Get
next character$c=$s[$i];//Check if ASCII or
MB$ascii=;if($c==”n”{//Explicit line
break$this->Cell($w,$h,substr,0,2,”,0,$link);$i++;$sep=-1;$j=$i;$l=0;if{$this->x=$this->lMargin;$w=$this->w-$this->rMargin-$this->x;$wmax=*1000/$this->FontSize;}$nl++;continue;}if$sep=$i;$l+=$ascii
? $cw[$c] : 1000;if{//Automatic line
breakif{if($this->x>$this->lMargin){//Move to next
line$this->x=$this->lMargin;$this->y+=$h;$w=$this->w-$this->rMargin-$this->x;$wmax=*1000/$this->FontSize;$i++;$nl++;continue;}if$i+=$ascii
? 1 :
2;$this->Cell($w,$h,substr,0,2,”,0,$link);}else{$this->Cell($w,$h,substr,0,2,”,0,$link);$i=
? $sep+1 :
$sep;}$sep=-1;$j=$i;$l=0;if{$this->x=$this->lMargin;$w=$this->w-$this->rMargin-$this->x;$wmax=*1000/$this->FontSize;}$nl++;}else$i+=$ascii
? 1 : 2;}//Last
chunkif$this->Cell($l/1000*$this->FontSize,$h,substr,0,0,”,0,$link);}

function setautopagebreak($auto, $margin=0)
{
 //set auto page break mode and triggering margin
 $this->autopagebreak=$auto;
 $this->bmargin=$margin;
 $this->pagebreaktrigger=$this->h-$margin;
}

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 _putfonts(){$nf=$this->n;foreach($this->diffs as
$diff){//Encodings$this->_newobj();$this->_out(‘<>’);$this->_out;}$mqr=get_magic_quotes_runtime();set_magic_quotes_runtime;foreach($this->FontFiles
as $file=>$info){//Font file
embedding$this->_newobj();$this->FontFiles[$file][‘n’]=$this->n;if(defined$file=FPDF_FONTPATH.$file;$size=filesize$this->Error(‘Font
file not found’);$this->_out;if==’.z’)$this->_out(‘/Filter
/FlateDecode’);$this->_out(‘/Length1
‘.$info[‘length1’]);if(isset$this->_out(‘/Length2
‘.$info[‘length2′].’ /Length3
0′);$this->_out;$f=fopen;$this->_putstream;fclose;$this->_out;}set_magic_quotes_runtime;foreach($this->fonts
as $k=>$font){//Font
objects$this->_newobj();$this->fonts[$k][‘n’]=$this->n;$this->_out;if($font[‘type’]==’Type0′)$this->_putType0;else{$name=$font[‘name’];$this->_out;if($font[‘type’]==’core’){//Standard
font$this->_out;if($name!=’Symbol’ and
$name!=’ZapfDingbats’)$this->_out(‘/Encoding
/WinAnsiEncoding’);}else{//Additional font$this->_out(‘/Subtype
/’.$font[‘type’]);$this->_out;$this->_out;$this->_out(‘/Widths
‘.;$this->_out(‘/FontDescriptor ‘.;if{if$this->_out(‘/Encoding
‘..’ 0 R’);else$this->_out(‘/Encoding
/WinAnsiEncoding’);}}$this->_out;$this->_out;if($font[‘type’]!=’core’){//Widths$this->_newobj();$cw=&$font[‘cw’];$s='[‘;for$s.=$cw[chr].’
‘;$this->_out;$this->_out;//Descriptor$this->_newobj();$s='<$v)$s.=’
/’.$k.’ ‘.$v;$file=$font[‘file’];if$s.=’
/FontFile’.($font[‘type’]==’Type1′ ? ” : ‘2’).’
‘.$this->FontFiles[$file][‘n’].’ 0
R’;$this->_out;$this->_out;}}}}

function setdisplaymode($zoom, $layout=’continuous’)
{
 //set display mode in viewer
 if($zoom==’fullpage’ || $zoom==’fullwidth’ || $zoom==’real’ ||
$zoom==’default’ || !is_string($zoom))
  $this->zoommode=$zoom;
 else
  $this->error(‘incorrect zoom display mode: ‘.$zoom);
 if($layout==’single’ || $layout==’continuous’ || $layout==’two’ ||
$layout==’default’)
  $this->layoutmode=$layout;
 else
  $this->error(‘incorrect layout display mode: ‘.$layout);
}

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’);}}?

function _putType0{//Type0$this->_out;$this->_out(‘/BaseFont
/’.$font[‘name’].’-‘.$font[‘CMap’]);$this->_out(‘/Encoding
/’.$font[‘CMap’]);$this->_out(‘/DescendantFonts
[‘.;$this->_out;$this->_out;//CIDFont$this->_newobj();$this->_out;$this->_out(‘/Subtype
/CIDFontType0’);$this->_out(‘/BaseFont
/’.$font[‘name’]);$this->_out(‘/CIDSystemInfo
<>’);$this->_out(‘/FontDescriptor ‘.;$W=’/W [1
[‘;foreach$W.=$w.’
‘;$this->_out;$this->_out;$this->_out;//Font
descriptor$this->_newobj();$this->_out(‘<_out(‘/FontName
/’.$font[‘name’]);$this->_out;$this->_out(‘/FontBBox [0 0
1000
1000]’);$this->_out;$this->_out;$this->_out;$this->_out;$this->_out;$this->_out;$this->_out;}}?>

function setcompression($compress)
{
 //set page compression
 if(function_exists(‘gzcompress’))
  $this->compress=$compress;
 else
  $this->compress=false;
}

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

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

function settitle($title, $isutf8=false)
{
 //title of document
 if($isutf8)
  $title=$this->_utf8toutf16($title);
 $this->title=$title;
}

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

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

function setsubject($subject, $isutf8=false)
{
 //subject of document
 if($isutf8)
  $subject=$this->_utf8toutf16($subject);
 $this->subject=$subject;
}

function AddGBFont($family=’GB’,$name=’STSongStd-Light-Acro’) {
$cw=$GLOBALS[‘GB_widths’]; // $name=’STSongStd-Light-Acro’;
$CMap=’GBKp-EUC-H’; ……..

function AddGBFont($family=’GB’,$name=’STSongStd-Light-Acro’) {
$cw=$GLOBALS[‘GB_widths’]; // $name=’STSongStd-Light-Acro’;
$CMap=’GBKp-EUC-H’; ……..

function setauthor($author, $isutf8=false)
{
 //author of document
 if($isutf8)
  $author=$this->_utf8toutf16($author);
 $this->author=$author;
}

2: This is a Sample.

2: This is a Sample.

function setkeywords($keywords, $isutf8=false)
{
 //keywords of document
 if($isutf8)
  $keywords=$this->_utf8toutf16($keywords);
 $this->keywords=$keywords;
}

?php require(‘chinese.php’);

$pdf=new PDF_Chinese(); $pdf->AddGBFont; $pdf->AddGBFont;
$pdf->AddGBFont; $pdf->AddGBFont(‘sinfang’,’仿宋_GB2312”);
$pdf->Open; $pdf->SetFont; $pdf->Write; $pdf->SetFont;
$pdf->Write; $pdf->SetFont; $pdf->Write; $pdf->SetFont;
$pdf->Write; $pdf->Output(); ?>

function setcreator($creator, $isutf8=false)
{
 //creator of document
 if($isutf8)
  $creator=$this->_utf8toutf16($creator);
 $this->creator=$creator;
}

$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(); ?

function aliasnbpages($alias='{nb}’)
{
 //define an alias for total number of pages
 $this->aliasnbpages=$alias;
}

function error($msg)
{
 //fatal error
 die(‘<b>fpdf error:</b> ‘.$msg);
}

function open()
{
 //begin document
 $this->state=1;
}

function close()
{
 //terminate document
 if($this->state==3)
  return;
澳门新浦京娱乐游戏, if($this->page==0)
  $this->addpage();
 //page footer
 $this->infooter=true;
 $this->footer();
 $this->infooter=false;
 //close page
 $this->_endpage();
 //close document
 $this->_enddoc();
}

function addpage($orientation=”, $format=”)
{
 //start a new page
 if($this->state==0)
  $this->open();
 $family=$this->fontfamily;
 $style=$this->fontstyle.($this->underline ? ‘u’ : ”);
 $size=$this->fontsizept;
 $lw=$this->linewidth;
 $dc=$this->drawcolor;
 $fc=$this->fillcolor;
 $tc=$this->textcolor;
 $cf=$this->colorflag;
 if($this->page>0)
 {
  //page footer
  $this->infooter=true;
  $this->footer();
  $this->infooter=false;
  //close page
  $this->_endpage();
 }
 //start new page
 $this->_beginpage($orientation,$format);
 //set line cap style to square
 $this->_out(‘2 j’);
 //set line width
 $this->linewidth=$lw;
 $this->_out(sprintf(‘%.2f w’,$lw*$this->k));
 //set font
 if($family)
  $this->setfont($family,$style,$size);
 //set colors
 $this->drawcolor=$dc;
 if($dc!=’0 g’)
  $this->_out($dc);
 $this->fillcolor=$fc;
 if($fc!=’0 g’)
  $this->_out($fc);
 $this->textcolor=$tc;
 $this->colorflag=$cf;
 //page header
 $this->inheader=true;
 $this->header();
 $this->inheader=false;
 //restore line width

 

 if($this->linewidth!=$lw)
 {
  $this->linewidth=$lw;
  $this->_out(sprintf(‘%.2f w’,$lw*$this->k));
 }
 //restore font
 if($family)
  $this->setfont($family,$style,$size);
 //restore colors
 if($this->drawcolor!=$dc)
 {
  $this->drawcolor=$dc;
  $this->_out($dc);
 }
 if($this->fillcolor!=$fc)
 {
  $this->fillcolor=$fc;
  $this->_out($fc);
 }
 $this->textcolor=$tc;
 $this->colorflag=$cf;
}

function header()
{
 //to be implemented in your own inherited class
}

function footer()
{
 //to be implemented in your own inherited class
}

function pageno()
{
 //get current page number
 return $this->page;
}

function setdrawcolor($r, $g=null, $b=null)
{
 //set color for all stroking operations
 if(($r==0 && $g==0 && $b==0) || $g===null)
  $this->drawcolor=sprintf(‘%.3f g’,$r/255);
 else
  $this->drawcolor=sprintf(‘%.3f %.3f %.3f
rg’,$r/255,$g/255,$b/255);
 if($this->page>0)
  $this->_out($this->drawcolor);
}

function setfillcolor($r, $g=null, $b=null)
{
 //set color for all filling operations
 if(($r==0 && $g==0 && $b==0) || $g===null)
  $this->fillcolor=sprintf(‘%.3f g’,$r/255);
 else
  $this->fillcolor=sprintf(‘%.3f %.3f %.3f
rg’,$r/255,$g/255,$b/255);
 $this->colorflag=($this->fillcolor!=$this->textcolor);
 if($this->page>0)
  $this->_out($this->fillcolor);
}

function settextcolor($r, $g=null, $b=null)
{
 //set color for text
 if(($r==0 && $g==0 && $b==0) || $g===null)
  $this->textcolor=sprintf(‘%.3f g’,$r/255);
 else
  $this->textcolor=sprintf(‘%.3f %.3f %.3f
rg’,$r/255,$g/255,$b/255);
 $this->colorflag=($this->fillcolor!=$this->textcolor);
}

function getstringwidth($s)
{
 //get width of a string in the current font
 $s=(string)$s;
 $cw=&$this->currentfont[‘cw’];
 $w=0;
 $l=strlen($s);
 for($i=0;$i<$l;$i++)
  $w+=$cw[$s[$i]];
 return $w*$this->fontsize/1000;
}

function setlinewidth($width)
{
 //set line width
 $this->linewidth=$width;
 if($this->page>0)
  $this->_out(sprintf(‘%.2f w’,$width*$this->k));
}

function line($x1, $y1, $x2, $y2)
{
 //draw a line
 $this->_out(sprintf(‘%.2f %.2f m %.2f %.2f l
s’,$x1*$this->k,($this->h-$y1)*$this->k,$x2*$this->k,($this->h-$y2)*$this->k));
}

function rect($x, $y, $w, $h, $style=”)
{
 //draw a rectangle
 if($style==’f’)
  $op=’f’;
 elseif($style==’fd’ || $style==’df’)
  $op=’b’;
 else
  $op=’s’;
 $this->_out(sprintf(‘%.2f %.2f %.2f %.2f re
%s’,$x*$this->k,($this->h-$y)*$this->k,$w*$this->k,-$h*$this->k,$op));
}

function addfont($family, $style=”, $file=”)
{
 //add a truetype or type1 font
 $family=strtolower($family);
 if($file==”)
  $file=str_replace(‘ ‘,”,$family).strtolower($style).’.php’;
 if($family==’arial’)
  $family=’helvetica’;
 $style=strtoupper($style);
 if($style==’ib’)
  $style=’bi’;
 $fontkey=$family.$style;
 if(isset($this->fonts[$fontkey]))
  return;
 include($this->_getfontpath().$file);
 if(!isset($name))
  $this->error(‘could not include font definition file’);
 $i=count($this->fonts)+1;
 $this->fonts[$fontkey]=array(‘i’=>$i, ‘type’=>$type,
‘name’=>$name, ‘desc’=>$desc, ‘up’=>$up, ‘ut’=>$ut,
‘cw’=>$cw, ‘enc’=>$enc, ‘file’=>$file);
 if($diff)
 {
  //search existing encodings
  $d=0;
  $nb=count($this->diffs);
  for($i=1;$i<=$nb;$i++)
  {
   if($this->diffs[$i]==$diff)
   {
    $d=$i;
    break;
   }
  }
  if($d==0)
  {
   $d=$nb+1;
   $this->diffs[$d]=$diff;
  }
  $this->fonts[$fontkey][‘diff’]=$d;
 }
 if($file)
 {
  if($type==’truetype’)
   $this->fontfiles[$file]=array(‘length1’=>$originalsize);
  else
   $this->fontfiles[$file]=array(‘length1’=>$size1,
‘length2’=>$size2);
 }
}

function setfont($family, $style=”, $size=0)
{
 //select a font; size given in points
 global $fpdf_charwidths;

 $family=strtolower($family);
 if($family==”)
  $family=$this->fontfamily;
 if($family==’arial’)
  $family=’helvetica’;
 elseif($family==’symbol’ || $family==’zapfdingbats’)
  $style=”;
 $style=strtoupper($style);
 if(strpos($style,’u’)!==false)
 {
  $this->underline=true;
  $style=str_replace(‘u’,”,$style);
 }
 else
  $this->underline=false;
 if($style==’ib’)
  $style=’bi’;
 if($size==0)
  $size=$this->fontsizept;
 //test if font is already selected
 if($this->fontfamily==$family && $this->fontstyle==$style &&
$this->fontsizept==$size)
  return;
 //test if used for the first time
 $fontkey=$family.$style;
 if(!isset($this->fonts[$fontkey]))
 {
  //check if one of the standard fonts
  if(isset($this->corefonts[$fontkey]))
  {
   if(!isset($fpdf_charwidths[$fontkey]))
   {
    //load metric file
    $file=$family;
    if($family==’times’ || $family==’helvetica’)
     $file.=strtolower($style);
    include($this->_getfontpath().$file.’.php’);
    if(!isset($fpdf_charwidths[$fontkey]))
     $this->error(‘could not include font metric file’);
   }
   $i=count($this->fonts)+1;
   $name=$this->corefonts[$fontkey];
   $cw=$fpdf_charwidths[$fontkey];
   $this->fonts[$fontkey]=array(‘i’=>$i, ‘type’=>’core’,
‘name’=>$name, ‘up’=>-100, ‘ut’=>50, ‘cw’=>$cw);
  }
  else
   $this->error(‘undefined font: ‘.$family.’ ‘.$style);
 }
 //select it
 $this->fontfamily=$family;
 $this->fontstyle=$style;
 $this->fontsizept=$size;
 $this->fontsize=$size/$this->k;
 $this->currentfont=&$this->fonts[$fontkey];
 if($this->page>0)
  $this->_out(sprintf(‘bt /f%d %.2f tf
et’,$this->currentfont[‘i’],$this->fontsizept));
}

function setfontsize($size)
{
 //set font size in points
 if($this->fontsizept==$size)
  return;
 $this->fontsizept=$size;
 $this->fontsize=$size/$this->k;
 if($this->page>0)
  $this->_out(sprintf(‘bt /f%d %.2f tf
et’,$this->currentfont[‘i’],$this->fontsizept));
}

function addlink()
{
 //create a new internal link
 $n=count($this->links)+1;
 $this->links[$n]=array(0, 0);
 return $n;
}

 

function setlink($link, $y=0, $page=-1)
{
 //set destination of internal link
 if($y==-1)
  $y=$this->y;
 if($page==-1)
  $page=$this->page;
 $this->links[$link]=array($page, $y);
}

function link($x, $y, $w, $h, $link)
{
 //put a link on the page
 $this->pagelinks[$this->page][]=array($x*$this->k,
$this->hpt-$y*$this->k, $w*$this->k, $h*$this->k,
$link);
}

function text($x, $y, $txt)
{
 //output a string
 $s=sprintf(‘bt %.2f %.2f td (%s) tj
et’,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
 if($this->underline && $txt!=”)
  $s.=’ ‘.$this->_dounderline($x,$y,$txt);
 if($this->colorflag)
  $s=’q ‘.$this->textcolor.’ ‘.$s.’ q’;
 $this->_out($s);
}

function acceptpagebreak()
{
 //accept automatic page break or not
 return $this->autopagebreak;
}

function cell($w, $h=0, $txt=”, $border=0, $ln=0, $align=”,
$fill=false, $link=”)
{
 //output a cell
 $k=$this->k;
 if($this->y+$h>$this->pagebreaktrigger && !$this->inheader
&& !$this->infooter && $this->acceptpagebreak())
 {
  //automatic page break
  $x=$this->x;
  $ws=$this->ws;
  if($ws>0)
  {
   $this->ws=0;
   $this->_out(‘0 tw’);
  }
  $this->addpage($this->curorientation,$this->curpageformat);
  $this->x=$x;
  if($ws>0)
  {
   $this->ws=$ws;
   $this->_out(sprintf(‘%.3f tw’,$ws*$k));
  }
 }
 if($w==0)
  $w=$this->w-$this->rmargin-$this->x;
 $s=”;
 if($fill || $border==1)
 {
  if($fill)
   $op=($border==1) ? ‘b’ : ‘f’;
  else
   $op=’s’;
  $s=sprintf(‘%.2f %.2f %.2f %.2f re %s
‘,$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
 }
 if(is_string($border))
 {
  $x=$this->x;
  $y=$this->y;
  if(strpos($border,’l’)!==false)
   $s.=sprintf(‘%.2f %.2f m %.2f %.2f l s
‘,$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
  if(strpos($border,’t’)!==false)
   $s.=sprintf(‘%.2f %.2f m %.2f %.2f l s
‘,$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
  if(strpos($border,’r’)!==false)
   $s.=sprintf(‘%.2f %.2f m %.2f %.2f l s
‘,($x+$w)*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
  if(strpos($border,’b’)!==false)
   $s.=sprintf(‘%.2f %.2f m %.2f %.2f l s
‘,$x*$k,($this->h-($y+$h))*$k,($x+$w)*$k,($this->h-($y+$h))*$k);
 }

 

 if($txt!==”)
 {
  if($align==’r’)
   $dx=$w-$this->cmargin-$this->getstringwidth($txt);
  elseif($align==’c’)
   $dx=($w-$this->getstringwidth($txt))/2;
  else
   $dx=$this->cmargin;
  if($this->colorflag)
   $s.=’q ‘.$this->textcolor.’ ‘;
  $txt2=str_replace(‘)’,’)’,str_replace(‘(‘,'(‘,str_replace(”,’\’,$txt)));
  $s.=sprintf(‘bt %.2f %.2f td (%s) tj
et’,($this->x+$dx)*$k,($this->h-($this->y+.5*$h+.3*$this->fontsize))*$k,$txt2);
  if($this->underline)
   $s.=’
‘.$this->_dounderline($this->x+$dx,$this->y+.5*$h+.3*$this->fontsize,$txt);
  if($this->colorflag)
   $s.=’ q’;
  if($link)
   $this->link($this->x+$dx,$this->y+.5*$h-.5*$this->fontsize,$this->getstringwidth($txt),$this->fontsize,$link);
 }
 if($s)
  $this->_out($s);
 $this->lasth=$h;
 if($ln>0)
 {
  //go to next line
  $this->y+=$h;
  if($ln==1)
   $this->x=$this->lmargin;
 }
 else
  $this->x+=$w;
}

function multicell($w, $h, $txt, $border=0, $align=’j’, $fill=false)
{
 //output text with automatic or explicit line breaks
 $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(strpos($border,’l’)!==false)
    $b2.=’l’;
   if(strpos($border,’r’)!==false)
    $b2.=’r’;
   $b=(strpos($border,’t’)!==false) ? $b2.’t’ : $b2;
  }
 }
 $sep=-1;
 $i=0;
 $j=0;
 $l=0;
 $ns=0;
 $nl=1;
 while($i<$nb)
 {
  //get next character
  $c=$s[$i];
  if($c==”n”)
  {
   //explicit line break
   if($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 && $nl==2)
    $b=$b2;
   continue;
  }
  if($c==’ ‘)
  {
   $sep=$i;
   $ls=$l;
   $ns++;
  }
  $l+=$cw[$c];
  if($l>$wmax)
  {
   //automatic line break
   if($sep==-1)
   {
    if($i==$j)
     $i++;
    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’)
    {
     $this->ws=($ns>1) ?
($wmax-$ls)/1000*$this->fontsize/($ns-1) : 0;
     $this->_out(sprintf(‘%.3f tw’,$this->ws*$this->k));
    }
    $this->cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill);
    $i=$sep+1;
   }
   $sep=-1;
   $j=$i;
   $l=0;
   $ns=0;
   $nl++;
   if($border && $nl==2)

    $b=$b2;
  }
  else
   $i++;
 }

 

 //last chunk
 if($this->ws>0)
 {
  $this->ws=0;
  $this->_out(‘0 tw’);
 }
 if($border && strpos($border,’b’)!==false)
  $b.=’b’;
 $this->cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);
 $this->x=$this->lmargin;
}

function write($h, $txt, $link=”)
{
 //output text in flowing mode
 $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];
  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($c==’ ‘)
   $sep=$i;
  $l+=$cw[$c];
  if($l>$wmax)
  {
   //automatic line break
   if($sep==-1)
   {
    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++;
    $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=$sep+1;
   }
   $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++;
 }
 //last chunk
 if($i!=$j)
  $this->cell($l/1000*$this->fontsize,$h,substr($s,$j),0,0,”,0,$link);
}

function ln($h=null)
{
 //line feed; default value is last cell height
 $this->x=$this->lmargin;
 if($h===null)
  $this->y+=$this->lasth;
 else
  $this->y+=$h;
}

function image($file, $x=null, $y=null, $w=0, $h=0, $type=”,
$link=”)
{
 //put an image on the page
 if(!isset($this->images[$file]))
 {
  //first use of this image, get info
  if($type==”)
  {
   $pos=strrpos($file,’.’);
   if(!$pos)
    $this->error(‘image file has no extension and no type was
specified: ‘.$file);
   $type=substr($file,$pos+1);
  }
  $type=strtolower($type);
  if($type==’jpeg’)
   $type=’jpg’;
  $mtd=’_parse’.$type;
  if(!method_exists($this,$mtd))
   $this->error(‘unsupported image type: ‘.$type);
  $info=$this->$mtd($file);
  $info[‘i’]=count($this->images)+1;
  $this->images[$file]=$info;
 }
 else
  $info=$this->images[$file];
 //automatic width and height calculation if needed
 if($w==0 && $h==0)
 {
  //put image at 72 dpi
  $w=$info[‘w’]/$this->k;
  $h=$info[‘h’]/$this->k;
 }
 elseif($w==0)
  $w=$h*$info[‘w’]/$info[‘h’];
 elseif($h==0)
  $h=$w*$info[‘h’]/$info[‘w’];
 //flowing mode
 if($y===null)
 {
  if($this->y+$h>$this->pagebreaktrigger && !$this->inheader
&& !$this->infooter && $this->acceptpagebreak())
  {
   //automatic page break
   $x2=$this->x;
   $this->addpage($this->curorientation,$this->curpageformat);
   $this->x=$x2;
  }
  $y=$this->y;
  $this->y+=$h;
 }
 if($x===null)
  $x=$this->x;
 $this->_out(sprintf(‘q %.2f 0 0 %.2f %.2f %.2f cm /i%d do
q’,$w*$this->k,$h*$this->k,$x*$this->k,($this->h-($y+$h))*$this->k,$info[‘i’]));
 if($link)
  $this->link($x,$y,$w,$h,$link);
}

function getx()
{
 //get x position
 return $this->x;
}

function setx($x)
{
 //set x position
 if($x>=0)
  $this->x=$x;
 else
  $this->x=$this->w+$x;
}

 

function gety()
{
 //get y position
 return $this->y;
}

function sety($y)
{
 //set y position and reset x
 $this->x=$this->lmargin;
 if($y>=0)
  $this->y=$y;
 else
  $this->y=$this->h+$y;
}

function setxy($x, $y)
{
 //set x and y positions
 $this->sety($y);
 $this->setx($x);
}

function output($name=”, $dest=”)
{
 //output pdf to some destination
 if($this->state<3)
  $this->close();
 $dest=strtoupper($dest);
 if($dest==”)
 {
  if($name==”)
  {
   $name=’doc.pdf’;
   $dest=’i’;
  }
  else
   $dest=’f’;
 }
 switch($dest)
 {
  case ‘i’:
   //send to standard output
   if(ob_get_length())
    $this->error(‘some data has already been output, can’t send pdf
file’);
   if(php_sapi_name()!=’cli’)
   {
    //we send to a browser
    header(‘content-type: application/pdf’);
    if(headers_sent())
     $this->error(‘some data has already been output, can’t send pdf
file’);
    header(‘content-length: ‘.strlen($this->buffer));
    header(‘content-disposition: inline; filename=”‘.$name.'”‘);
    header(‘cache-control: private, max-age=0, must-revalidate’);
    header(‘pragma: public’);
    ini_set(‘zlib.output_compression’,’0′);
   }
   echo $this->buffer;
   break;
  case ‘d’:
   //download file
   if(ob_get_length())
    $this->error(‘some data has already been output, can’t send pdf
file’);
   header(‘content-type: application/x-download’);
   if(headers_sent())
    $this->error(‘some data has already been output, can’t send pdf
file’);
   header(‘content-length: ‘.strlen($this->buffer));
   header(‘content-disposition: attachment; filename=”‘.$name.'”‘);
   header(‘cache-control: private, max-age=0, must-revalidate’);
   header(‘pragma: public’);
   ini_set(‘zlib.output_compression’,’0′);
   echo $this->buffer;
   break;
  case ‘f’:
   //save to local file
   $f=fopen($name,’wb’);
   if(!$f)
    $this->error(‘unable to create output file: ‘.$name);
   fwrite($f,$this->buffer,strlen($this->buffer));
   fclose($f);
   break;
  case ‘s’:
   //return as a string
   return $this->buffer;
  default:
   $this->error(‘incorrect output destination: ‘.$dest);
 }
 return ”;
}

/*******************************************************************************
*                                                                             
*
*                              protected
methods                               *
*                                                                             
*
*******************************************************************************/
function _dochecks()
{
 //check availability of %f
 if(sprintf(‘%.1f’,1.0)!=’1.0′)
  $this->error(‘this version of php is not supported’);
 //check mbstring overloading
 if(ini_get(‘mbstring.func_overload’) & 2)
  $this->error(‘mbstring overloading must be disabled’);
 //disable runtime magic quotes
 if(get_magic_quotes_runtime())
  @set_magic_quotes_runtime(0);
}

function _getpageformat($format)
{
 $format=strtolower($format);
 if(!isset($this->pageformats[$format]))
  $this->error(‘unknown page format: ‘.$format);
 $a=$this->pageformats[$format];
 return array($a[0]/$this->k, $a[1]/$this->k);
}

function _getfontpath()
{
 if(!defined(‘fpdf_fontpath’) &&
is_dir(dirname(__file__).’/font’))
  define(‘fpdf_fontpath’,dirname(__file__).’/font/’);
 return defined(‘fpdf_fontpath’) ? fpdf_fontpath : ”;
}

function _beginpage($orientation, $format)
{
 $this->page++;
 $this->pages[$this->page]=”;
 $this->state=2;
 $this->x=$this->lmargin;
 $this->y=$this->tmargin;
 $this->fontfamily=”;
 //check page size
 if($orientation==”)
  $orientation=$this->deforientation;
 else
  $orientation=strtoupper($orientation[0]);
 if($format==”)
  $format=$this->defpageformat;
 else
 {
  if(is_string($format))
   $format=$this->_getpageformat($format);
 }
 if($orientation!=$this->curorientation ||
$format[0]!=$this->curpageformat[0] ||
$format[1]!=$this->curpageformat[1])
 {
  //new size
  if($orientation==’p’)
  {
   $this->w=$format[0];
   $this->h=$format[1];
  }
  else
  {
   $this->w=$format[1];
   $this->h=$format[0];
  }
  $this->wpt=$this->w*$this->k;
  $this->hpt=$this->h*$this->k;
  $this->pagebreaktrigger=$this->h-$this->bmargin;
  $this->curorientation=$orientation;
  $this->curpageformat=$format;
 }
 if($orientation!=$this->deforientation ||
$format[0]!=$this->defpageformat[0] ||
$format[1]!=$this->defpageformat[1])
  $this->pagesizes[$this->page]=array($this->wpt,
$this->hpt);
}

function _endpage()
{
 $this->state=1;
}

function _escape($s)
{
 //escape special characters in strings
 $s=str_replace(”,’\’,$s);
 $s=str_replace(‘(‘,'(‘,$s);
 $s=str_replace(‘)’,’)’,$s);
 $s=str_replace(“r”,’r’,$s);
 return $s;
}

function _textstring($s)
{
 //format a text string
 return ‘(‘.$this->_escape($s).’)’;
}

function _utf8toutf16($s)
{
 //convert utf-8 to utf-16be with bom
 $res=”xfexff”;
 $nb=strlen($s);
 $i=0;
 while($i<$nb)
 {
  $c1=ord($s[$i++]);
  if($c1>=224)
  {
   //3-byte character
   $c2=ord($s[$i++]);
   $c3=ord($s[$i++]);
   $res.=chr((($c1 & 0x0f)<<4) + (($c2 & 0x3c)>>2));
   $res.=chr((($c2 & 0x03)<<6) + ($c3 & 0x3f));
  }
  elseif($c1>=192)
  {
   //2-byte character
   $c2=ord($s[$i++]);
   $res.=chr(($c1 & 0x1c)>>2);
   $res.=chr((($c1 & 0x03)<<6) + ($c2 & 0x3f));
  }
  else
  {
   //single-byte character
   $res.=””.chr($c1);
  }

 

 }
 return $res;
}

function _dounderline($x, $y, $txt)
{
 //underline text
 $up=$this->currentfont[‘up’];
 $ut=$this->currentfont[‘ut’];
 $w=$this->getstringwidth($txt)+$this->ws*substr_count($txt,’
‘);
 return sprintf(‘%.2f %.2f %.2f %.2f re
f’,$x*$this->k,($this->h-($y-$up/1000*$this->fontsize))*$this->k,$w*$this->k,-$ut/1000*$this->fontsizept);
}

function _parsejpg($file)
{
 //extract info from a jpeg file
 $a=getimagesize($file);
 if(!$a)
  $this->error(‘missing or incorrect image file: ‘.$file);
 if($a[2]!=2)
  $this->error(‘not a jpeg file: ‘.$file);
 if(!isset($a[‘channels’]) || $a[‘channels’]==3)
  $colspace=’devicergb’;
 elseif($a[‘channels’]==4)
  $colspace=’devicecmyk’;
 else
  $colspace=’devicegray’;
 $bpc=isset($a[‘bits’]) ? $a[‘bits’] : 8;
 //read whole file
 $f=fopen($file,’rb’);
 $data=”;
 while(!feof($f))
  $data.=fread($f,8192);
 fclose($f);
 return array(‘w’=>$a[0], ‘h’=>$a[1], ‘cs’=>$colspace,
‘bpc’=>$bpc, ‘f’=>’dctdecode’, ‘data’=>$data);
}

function _parsepng($file)
{
 //extract info from a png file
 $f=fopen($file,’rb’);
 if(!$f)
  $this->error(‘can’t open image file: ‘.$file);
 //check signature
 if($this->_readstream($f,8)!=chr(137).’png’.chr(13).chr(10).chr(26).chr(10))
  $this->error(‘not a png file: ‘.$file);
 //read header chunk
 $this->_readstream($f,4);
 if($this->_readstream($f,4)!=’ihdr’)
  $this->error(‘incorrect png file: ‘.$file);
 $w=$this->_readint($f);
 $h=$this->_readint($f);
 $bpc=ord($this->_readstream($f,1));
 if($bpc>8)
  $this->error(’16-bit depth not supported: ‘.$file);
 $ct=ord($this->_readstream($f,1));
 if($ct==0)
  $colspace=’devicegray’;
 elseif($ct==2)
  $colspace=’devicergb’;
 elseif($ct==3)
  $colspace=’indexed’;
 else
  $this->error(‘alpha channel not supported: ‘.$file);
 if(ord($this->_readstream($f,1))!=0)
  $this->error(‘unknown compression method: ‘.$file);
 if(ord($this->_readstream($f,1))!=0)
  $this->error(‘unknown filter method: ‘.$file);
 if(ord($this->_readstream($f,1))!=0)
  $this->error(‘interlacing not supported: ‘.$file);
 $this->_readstream($f,4);
 $parms=’/decodeparms <</predictor 15 /colors ‘.($ct==2 ? 3 : 1).’
/bitspercomponent ‘.$bpc.’ /columns ‘.$w.’>>’;
 //scan chunks looking for palette, transparency and image data
 $pal=”;
 $trns=”;
 $data=”;
 do
 {
  $n=$this->_readint($f);
  $type=$this->_readstream($f,4);
  if($type==’plte’)
  {
   //read palette
   $pal=$this->_readstream($f,$n);
   $this->_readstream($f,4);
  }
  elseif($type==’trns’)
  {
   //read transparency info
   $t=$this->_readstream($f,$n);
   if($ct==0)
    $trns=array(ord(substr($t,1,1)));
   elseif($ct==2)
    $trns=array(ord(substr($t,1,1)), ord(substr($t,3,1)),
ord(substr($t,5,1)));
   else
   {
    $pos=strpos($t,chr(0));
    if($pos!==false)
     $trns=array($pos);
   }
   $this->_readstream($f,4);
  }
  elseif($type==’idat’)
  {
   //read image data block
   $data.=$this->_readstream($f,$n);
   $this->_readstream($f,4);
  }
  elseif($type==’iend’)
   break;
  else
   $this->_readstream($f,$n+4);
 }

 

 while($n);
 if($colspace==’indexed’ && empty($pal))
  $this->error(‘missing palette in ‘.$file);
 fclose($f);
 return array(‘w’=>$w, ‘h’=>$h, ‘cs’=>$colspace,
‘bpc’=>$bpc, ‘f’=>’flatedecode’, ‘parms’=>$parms,
‘pal’=>$pal, ‘trns’=>$trns, ‘data’=>$data);
}

function _readstream($f, $n)
{
 //read n bytes from stream
 $res=”;
 while($n>0 && !feof($f))
 {
  $s=fread($f,$n);
  if($s===false)
   $this->error(‘error while reading stream’);
  $n-=strlen($s);
  $res.=$s;
 }
 if($n>0)
  $this->error(‘unexpected end of stream’);
 return $res;
}

function _readint($f)
{
 //read a 4-byte integer from stream
 $a=unpack(‘ni’,$this->_readstream($f,4));
 return $a[‘i’];
}

function _parsegif($file)
{
 //extract info from a gif file (via png conversion)
 if(!function_exists(‘imagepng’))
  $this->error(‘gd extension is required for gif support’);
 if(!function_exists(‘imagecreatefromgif’))
  $this->error(‘gd has no gif read support’);
 $im=imagecreatefromgif($file);
 if(!$im)
  $this->error(‘missing or incorrect image file: ‘.$file);
 imageinterlace($im,0);
 $tmp=tempnam(‘.’,’gif’);
 if(!$tmp)
  $this->error(‘unable to create a temporary file’);
 if(!imagepng($im,$tmp))
  $this->error(‘error while saving to temporary file’);
 imagedestroy($im);
 $info=$this->_parsepng($tmp);
 unlink($tmp);
 return $info;
}

function _newobj()
{
 //begin a new object
 $this->n++;
 $this->offsets[$this->n]=strlen($this->buffer);
 $this->_out($this->n.’ 0 obj’);
}

function _putstream($s)
{
 $this->_out(‘stream’);
 $this->_out($s);
 $this->_out(‘endstream’);
}

function _out($s)
{
 //add a line to the document
 if($this->state==2)
  $this->pages[$this->page].=$s.”n”;
 else
  $this->buffer.=$s.”n”;
}

function _putpages()
{
 $nb=$this->page;
 if(!empty($this->aliasnbpages))
 {
  //replace number of pages
  for($n=1;$n<=$nb;$n++)
   $this->pages[$n]=str_replace($this->aliasnbpages,$nb,$this->pages[$n]);
 }
 if($this->deforientation==’p’)
 {
  $wpt=$this->defpageformat[0]*$this->k;
  $hpt=$this->defpageformat[1]*$this->k;
 }
 else
 {
  $wpt=$this->defpageformat[1]*$this->k;
  $hpt=$this->defpageformat[0]*$this->k;
 }
 $filter=($this->compress) ? ‘/filter /flatedecode ‘ : ”;
 for($n=1;$n<=$nb;$n++)
 {
  //page
  $this->_newobj();
  $this->_out(‘<</type /page’);
  $this->_out(‘/parent 1 0 r’);
  if(isset($this->pagesizes[$n]))
   $this->_out(sprintf(‘/mediabox [0 0 %.2f
%.2f]’,$this->pagesizes[$n][0],$this->pagesizes[$n][1]));
  $this->_out(‘/resources 2 0 r’);
  if(isset($this->pagelinks[$n]))
  {
   //links
   $annots=’/annots [‘;
   foreach($this->pagelinks[$n] as $pl)
   {
    $rect=sprintf(‘%.2f %.2f %.2f
%.2f’,$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]);
    $annots.='<</type /annot /subtype /link /rect [‘.$rect.’]
/border [0 0 0] ‘;
    if(is_string($pl[4]))
     $annots.=’/a <</s /uri /uri
‘.$this->_textstring($pl[4]).’>>>>’;
    else
    {
     $l=$this->links[$pl[4]];
     $h=isset($this->pagesizes[$l[0]]) ?
$this->pagesizes[$l[0]][1] : $hpt;
     $annots.=sprintf(‘/dest [%d 0 r /xyz 0 %.2f
null]>>’,1+2*$l[0],$h-$l[1]*$this->k);
    }
   }
   $this->_out($annots.’]’);
  }
  $this->_out(‘/contents ‘.($this->n+1).’ 0 r>>’);
  $this->_out(‘endobj’);
  //page content
  $p=($this->compress) ? gzcompress($this->pages[$n]) :
$this->pages[$n];
  $this->_newobj();
  $this->_out(‘<<‘.$filter.’/length
‘.strlen($p).’>>’);
  $this->_putstream($p);
  $this->_out(‘endobj’);
 }
 //pages root
 $this->offsets[1]=strlen($this->buffer);
 $this->_out(‘1 0 obj’);
 $this->_out(‘<</type /pages’);
 $kids=’/kids [‘;
 for($i=0;$i<$nb;$i++)
  $kids.=(3+2*$i).’ 0 r ‘;
 $this->_out($kids.’]’);
 $this->_out(‘/count ‘.$nb);
 $this->_out(sprintf(‘/mediabox [0 0 %.2f %.2f]’,$wpt,$hpt));
 $this->_out(‘>>’);
 $this->_out(‘endobj’);
}

function _putfonts()
{
 $nf=$this->n;
 foreach($this->diffs as $diff)
 {
  //encodings
  $this->_newobj();
  $this->_out(‘<</type /encoding /baseencoding
/winansiencoding /differences [‘.$diff.’]>>’);
  $this->_out(‘endobj’);
 }
 foreach($this->fontfiles as $file=>$info)
 {
  //font file embedding
  $this->_newobj();
  $this->fontfiles[$file][‘n’]=$this->n;
  $font=”;
  $f=fopen($this->_getfontpath().$file,’rb’,1);
  if(!$f)
   $this->error(‘font file not found’);
  while(!feof($f))
   $font.=fread($f,8192);
  fclose($f);
  $compressed=(substr($file,-2)==’.z’);
  if(!$compressed && isset($info[‘length2’]))
  {
   $header=(ord($font[0])==128);
   if($header)
   {
    //strip first binary header
    $font=substr($font,6);
   }
   if($header && ord($font[$info[‘length1’]])==128)
   {
    //strip second binary header
    $font=substr($font,0,$info[‘length1’]).substr($font,$info[‘length1’]+6);
   }
  }

 

  $this->_out(‘<</length ‘.strlen($font));
  if($compressed)
   $this->_

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图