【php开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了php开源代码-ufpdf.php的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
<?php
/*******************************************************************************
* Software: UFPDF, Unicode Free PDF generator *
* Version: 0.1 *
* based on FPDF 1.52 by Olivier PLATHEY *
* Date: 2004-09-01 *
* Author: Steven Wittens <steven@acko.net> *
* License: GPL *
* *
* UFPDF is a modification of FPDF to support Unicode through UTF-8. *
* *
*******************************************************************************/
if(!class_exists('UFPDF'))
{
define('UFPDF_VERSION','0.1');
include_once './libraries/fpdf/fpdf.php';
class UFPDF extends FPDF
{
/*******************************************************************************
* *
* Public methods *
* *
*******************************************************************************/
function UFPDF($orientation='P',$unit='mm',$format='A4')
{
FPDF::FPDF($orientation, $unit, $format);
}
function GetStringWidth($s)
{
//Get width of a string in the current font
$s = (string)$s;
$codepoints=$this->utf8_to_codepoints($s);
$cw=&$this->CurrentFont['cw'];
$w=0;
foreach($codepoints as $cp)
$w+=isset($cw[$cp])?$cw[$cp]:0;
return $w*$this->FontSize/1000;
}
function AddFont($family,$style='',$file='')
{
//Add a TrueType or Type1 font
$family=strtolower($family);
if($family=='arial')
$family='helvetica';
$style=strtoupper($style);
if($style=='IB')
$style='BI';
if(isset($this->fonts[$family.$style]))
$this->Error('Font already added: '.$family.' '.$style);
if($file=='')
$file=str_replace(' ','',$family).strtolower($style).'.php';
if(defined('FPDF_FONTPATH'))
$file=FPDF_FONTPATH.$file;
include($file);
if(!isset($name))
$this->Error('Could not include font definition file');
$i=count($this->fonts)+1;
$this->fonts[$family.$style]=array('i'=>$i,'type'=>$type,'name'=>$name,'desc'=>$desc,'up'=>$up,'ut'=>$ut,'cw'=>$cw,'file'=>$file,'ctg'=>$ctg);
if($file)
{
if($type=='TrueTypeUnicode')
$this->FontFiles[$file]=array('length1'=>$originalsize);
else
$this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2);
}
}
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->_escapetext($txt));
if($this->underline and $txt!='')
$s.=' '.$this->_dounderline($x,$y,$this->GetStringWidth($txt),$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=0,$link='')
{
//Output a cell
$k=$this->k;
if($this->y+$h>$this->PageBreakTrigger and !$this->InFooter and $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->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==1 or $border==1)
{
if($fill==1)
$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(is_int(strpos($border,'L')))
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,$x*$k,($this->h-($y+$h))*$k);
if(is_int(strpos($border,'T')))
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',$x*$k,($this->h-$y)*$k,($x+$w)*$k,($this->h-$y)*$k);
if(is_int(strpos($border,'R')))
$s.=sprintf('%.2f %.2f m %.2f %.2f l S ',