⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fpdf.php

📁 最近在做软交换时研究的一个软交换的东东
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?php/******************************************************************************** Logiciel : FPDF                                                              ** Version :  1.52                                                              ** Date :     30/12/2003                                                        ** Auteur :   Olivier PLATHEY                                                   ** Licence :  Freeware                                                          **                                                                              ** Vous pouvez utiliser et modifier ce logiciel comme vous le souhaitez.        ********************************************************************************/if(!class_exists('FPDF')){define('FPDF_VERSION','1.52');class FPDF{//Private propertiesvar $page;               //current page numbervar $n;                  //current object numbervar $offsets;            //array of object offsetsvar $buffer;             //buffer holding in-memory PDFvar $pages;              //array containing pagesvar $state;              //current document statevar $compress;           //compression flagvar $DefOrientation;     //default orientationvar $CurOrientation;     //current orientationvar $OrientationChanges; //array indicating orientation changesvar $k;                  //scale factor (number of points in user unit)var $fwPt,$fhPt;         //dimensions of page format in pointsvar $fw,$fh;             //dimensions of page format in user unitvar $wPt,$hPt;           //current dimensions of page in pointsvar $w,$h;               //current dimensions of page in user unitvar $lMargin;            //left marginvar $tMargin;            //top marginvar $rMargin;            //right marginvar $bMargin;            //page break marginvar $cMargin;            //cell marginvar $x,$y;               //current position in user unit for cell positioningvar $lasth;              //height of last cell printedvar $LineWidth;          //line width in user unitvar $CoreFonts;          //array of standard font namesvar $fonts;              //array of used fontsvar $FontFiles;          //array of font filesvar $diffs;              //array of encoding differencesvar $images;             //array of used imagesvar $PageLinks;          //array of links in pagesvar $links;              //array of internal linksvar $FontFamily;         //current font familyvar $FontStyle;          //current font stylevar $underline;          //underlining flagvar $CurrentFont;        //current font infovar $FontSizePt;         //current font size in pointsvar $FontSize;           //current font size in user unitvar $DrawColor;          //commands for drawing colorvar $FillColor;          //commands for filling colorvar $TextColor;          //commands for text colorvar $ColorFlag;          //indicates whether fill and text colors are differentvar $ws;                 //word spacingvar $AutoPageBreak;      //automatic page breakingvar $PageBreakTrigger;   //threshold used to trigger page breaksvar $InFooter;           //flag set when processing footervar $ZoomMode;           //zoom display modevar $LayoutMode;         //layout display modevar $title;              //titlevar $subject;            //subjectvar $author;             //authorvar $keywords;           //keywordsvar $creator;            //creatorvar $AliasNbPages;       //alias for total number of pages/********************************************************************************                                                                              **                               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->OrientationChanges=array();	$this->state=0;	$this->fonts=array();	$this->FontFiles=array();	$this->diffs=array();	$this->images=array();	$this->links=array();	$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')		$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	if(is_string($format))	{		$format=strtolower($format);		if($format=='a3')			$format=array(841.89,1190.55);		elseif($format=='a4')			$format=array(595.28,841.89);		elseif($format=='a5')			$format=array(420.94,595.28);		elseif($format=='letter')			$format=array(612,792);		elseif($format=='legal')			$format=array(612,1008);		else			$this->Error('Unknown page format: '.$format);		$this->fwPt=$format[0];		$this->fhPt=$format[1];	}	else	{		$this->fwPt=$format[0]*$this->k;		$this->fhPt=$format[1]*$this->k;	}	$this->fw=$this->fwPt/$this->k;	$this->fh=$this->fhPt/$this->k;	//Page orientation	$orientation=strtolower($orientation);	if($orientation=='p' or $orientation=='portrait')	{		$this->DefOrientation='P';		$this->wPt=$this->fwPt;		$this->hPt=$this->fhPt;	}	elseif($orientation=='l' or $orientation=='landscape')	{		$this->DefOrientation='L';		$this->wPt=$this->fhPt;		$this->hPt=$this->fwPt;	}	else		$this->Error('Incorrect orientation: '.$orientation);	$this->CurOrientation=$this->DefOrientation;	$this->w=$this->wPt/$this->k;	$this->h=$this->hPt/$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');	//Compression	$this->SetCompression(true);}function SetMargins($left,$top,$right=-1){	//Set left, top and right margins	$this->lMargin=$left;	$this->tMargin=$top;	if($right==-1)		$right=$left;	$this->rMargin=$right;}function SetLeftMargin($margin){	//Set left margin	$this->lMargin=$margin;	if($this->page>0 and $this->x<$margin)		$this->x=$margin;}function SetTopMargin($margin){	//Set top margin	$this->tMargin=$margin;}function SetRightMargin($margin){	//Set right margin	$this->rMargin=$margin;}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 SetDisplayMode($zoom,$layout='continuous'){	//Set display mode in viewer	if($zoom=='fullpage' or $zoom=='fullwidth' or $zoom=='real' or $zoom=='default' or !is_string($zoom))		$this->ZoomMode=$zoom;	else		$this->Error('Incorrect zoom display mode: '.$zoom);	if($layout=='single' or $layout=='continuous' or $layout=='two' or $layout=='default')		$this->LayoutMode=$layout;	else		$this->Error('Incorrect layout display mode: '.$layout);}function SetCompression($compress){	//Set page compression	if(function_exists('gzcompress'))		$this->compress=$compress;	else		$this->compress=false;}function SetTitle($title){	//Title of document	$this->title=$title;}function SetSubject($subject){	//Subject of document	$this->subject=$subject;}function SetAuthor($author){	//Author of document	$this->author=$author;}function SetKeywords($keywords){	//Keywords of document	$this->keywords=$keywords;}function SetCreator($creator){	//Creator of document	$this->creator=$creator;}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	if($this->state==0)		$this->_begindoc();}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=''){	//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);	//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->Header();	//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=-1,$b=-1){	//Set color for all stroking operations	if(($r==0 and $g==0 and $b==0) or $g==-1)		$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=-1,$b=-1){	//Set color for all filling operations	if(($r==0 and $g==0 and $b==0) or $g==-1)		$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=-1,$b=-1){	//Set color for text	if(($r==0 and $g==0 and $b==0) or $g==-1)		$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' or $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($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,'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[$family.$style]['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' or $family=='zapfdingbats')		$style='';	$style=strtoupper($style);	if(is_int(strpos($style,'U')))	{		$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 and $this->FontStyle==$style and $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]))		{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -