?? fpdf.php
字號:
<?php/******************************************************************************** Software: FPDF ** Version: 1.52 ** Date: 2003-12-30 ** Author: Olivier PLATHEY ** License: Freeware ** ** You may use, modify and redistribute this software as you wish. ********************************************************************************/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)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -