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

📄 tcpdf.php

📁 简介:一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 5 页
字号:
			$this->header_title = $ht;			$this->header_string = $hs;		}				/**	 	 * Set header margin.		 * (minimum distance between header and top page margin)		 * @param int $hm distance in millimeters		*/		function setHeaderMargin($hm=10) {			$this->header_margin = $hm;		}				/**	 	 * Set footer margin.		 * (minimum distance between footer and bottom page margin)		 * @param int $fm distance in millimeters		*/		function setFooterMargin($fm=10) {			$this->footer_margin = $fm;		}				/**	 	 * This method is used to render the page header.	 	 * It is automatically called by AddPage() and could be overwritten in your own inherited class.		 */		function Header() {			if ($this->print_header) {								if (!isset($this->original_lMargin)) {					$this->original_lMargin = $this->lMargin;				}				if (!isset($this->original_rMargin)) {					$this->original_rMargin = $this->rMargin;				}								//set current position				$this->SetXY($this->original_lMargin, $this->header_margin);								if (($this->header_logo) AND ($this->header_logo != K_BLANK_IMAGE)) {					$this->Image(K_PATH_IMAGES.$this->header_logo, $this->original_lMargin, $this->header_margin, $this->header_logo_width);				}				else {					$this->img_rb_y = $this->GetY();				}								$cell_height = round((K_CELL_HEIGHT_RATIO * $this->header_font[2]) / $this->k, 2);								$header_x = $this->original_lMargin + ($this->header_logo_width * 1.05); //set left margin for text data cell								// header title				$this->SetFont($this->header_font[0], 'B', $this->header_font[2] + 1);				$this->SetX($header_x);				$this->Cell($this->header_width, $cell_height, $this->header_title, 0, 1, 'L'); 								// header string				$this->SetFont($this->header_font[0], $this->header_font[1], $this->header_font[2]);				$this->SetX($header_x);				$this->MultiCell($this->header_width, $cell_height, $this->header_string, 0, 'L', 0);								// print an ending header line				if (empty($this->header_width)) {					//set style for cell border					$this->SetLineWidth(0.3);					$this->SetDrawColor(0, 0, 0);					$this->SetY(1 + max($this->img_rb_y, $this->GetY()));					$this->SetX($this->original_lMargin);					$this->Cell(0, 0, '', 'T', 0, 'C'); 				}								//restore position				$this->SetXY($this->original_lMargin, $this->tMargin);			}		}				/**	 	 * This method is used to render the page footer. 	 	 * It is automatically called by AddPage() and could be overwritten in your own inherited class.		 */		function Footer() {			if ($this->print_footer) {								if (!isset($this->original_lMargin)) {					$this->original_lMargin = $this->lMargin;				}				if (!isset($this->original_rMargin)) {					$this->original_rMargin = $this->rMargin;				}								//set font				$this->SetFont($this->footer_font[0], $this->footer_font[1] , $this->footer_font[2]);				//set style for cell border				$line_width = 0.3;				$this->SetLineWidth($line_width);				$this->SetDrawColor(0, 0, 0);								$footer_height = round((K_CELL_HEIGHT_RATIO * $this->footer_font[2]) / $this->k, 2); //footer height				//get footer y position				$footer_y = $this->h - $this->footer_margin - $footer_height;				//set current position				$this->SetXY($this->original_lMargin, $footer_y); 								//print document barcode				if ($this->barcode) {					$this->Ln();					$barcode_width = round(($this->w - $this->original_lMargin - $this->original_rMargin)); //max width					$this->writeBarcode($this->original_lMargin, $footer_y + $line_width, $barcode_width, $footer_height - $line_width, "C128B", false, false, 2, $this->barcode);				}								$this->SetXY($this->original_lMargin, $footer_y); 								//Print page number				$this->Cell(0, $footer_height, $this->l['w_page']." ".$this->PageNo().' / {nb}', 'T', 0, 'R'); 			}		}				/**		* Returns the current page number.		* @return int page number		* @since 1.0		* @see AliasNbPages()		*/		function PageNo() {			//Get current page number			return $this->page;		}		/**		* Defines the color used for all drawing operations (lines, rectangles and cell borders). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.		* @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255		* @param int $g Green component (between 0 and 255)		* @param int $b Blue component (between 0 and 255)		* @since 1.3		* @see SetFillColor(), SetTextColor(), Line(), Rect(), Cell(), MultiCell()		*/		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);			}		}		/**		* Defines the color used for all filling operations (filled rectangles and cell backgrounds). It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.		* @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255		* @param int $g Green component (between 0 and 255)		* @param int $b Blue component (between 0 and 255)		* @param boolean $storeprev if true stores the RGB array on $prevFillColor variable.		* @since 1.3		* @see SetDrawColor(), SetTextColor(), Rect(), Cell(), MultiCell()		*/		function SetFillColor($r, $g=-1, $b=-1, $storeprev=false) {			//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);			}			if ($storeprev) {				// store color as previous value				$this->prevFillColor = array($r, $g, $b);			}		}		/**		* Defines the color used for text. It can be expressed in RGB components or gray scale. The method can be called before the first page is created and the value is retained from page to page.		* @param int $r If g et b are given, red component; if not, indicates the gray level. Value between 0 and 255		* @param int $g Green component (between 0 and 255)		* @param int $b Blue component (between 0 and 255)		* @param boolean $storeprev if true stores the RGB array on $prevTextColor variable.		* @since 1.3		* @see SetDrawColor(), SetFillColor(), Text(), Cell(), MultiCell()		*/		function SetTextColor($r, $g=-1, $b=-1, $storeprev=false) {			//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);			if ($storeprev) {				// store color as previous value				$this->prevTextColor = array($r, $g, $b);			}		}		/**		* Returns the length of a string in user unit. A font must be selected.<br>		* Support UTF-8 Unicode [Nicola Asuni, 2005-01-02]		* @param string $s The string whose length is to be computed		* @return int		* @since 1.2		*/		function GetStringWidth($s) {			//Get width of a string in the current font			$s = (string)$s;			$cw = &$this->CurrentFont['cw'];			$w = 0;			if($this->isunicode) {				$unicode = $this->UTF8StringToArray($s);				foreach($unicode as $char) {					if (isset($cw[$char])) {						$w+=$cw[$char];					} elseif(isset($cw[ord($char)])) {						$w+=$cw[ord($char)];					} elseif(isset($cw[chr($char)])) {						$w+=$cw[chr($char)];					} elseif(isset($this->CurrentFont['desc']['MissingWidth'])) {						$w += $this->CurrentFont['desc']['MissingWidth']; // set default size					} else {						$w += 500;					}				}			} else {				$l = strlen($s);				for($i=0; $i<$l; $i++) {					if (isset($cw[$s{$i}])) {						$w += $cw[$s{$i}];					} else if (isset($cw[ord($s{$i})])) {						$w += $cw[ord($s{$i})];					}				}			}			return ($w * $this->FontSize / 1000);		}		/**		* Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.		* @param float $width The width.		* @since 1.0		* @see Line(), Rect(), Cell(), MultiCell()		*/		function SetLineWidth($width) {			//Set line width			$this->LineWidth=$width;			if($this->page>0) {				$this->_out(sprintf('%.2f w',$width*$this->k));			}		}		/**		* Draws a line between two points.		* @param float $x1 Abscissa of first point		* @param float $y1 Ordinate of first point		* @param float $x2 Abscissa of second point		* @param float $y2 Ordinate of second point		* @since 1.0		* @see SetLineWidth(), SetDrawColor()		*/		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));		}		/**		* Outputs a rectangle. It can be drawn (border only), filled (with no border) or both.		* @param float $x Abscissa of upper-left corner		* @param float $y Ordinate of upper-left corner		* @param float $w Width		* @param float $h Height		* @param string $style Style of rendering. Possible values are:<ul><li>D or empty string: draw (default)</li><li>F: fill</li><li>DF or FD: draw and fill</li></ul>		* @since 1.0		* @see SetLineWidth(), SetDrawColor(), SetFillColor()		*/		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));		}		/**		* Imports a TrueType or Type1 font and makes it available. It is necessary to generate a font definition file first with the makefont.php utility. The definition file (and the font file itself when embedding) must be present either in the current directory or in the one indicated by FPDF_FONTPATH if the constant is defined. If it could not be found, the error "Could not include font definition file" is generated.		* Support UTF-8 Unicode [Nicola Asuni, 2005-01-02].		* <b>Example</b>:<br />		* <pre>		* $pdf->AddFont('Comic','I');		* // is equivalent to:		* $pdf->AddFont('Comic','I','comici.php');		* </pre>		* @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.		* @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul>		* @param string $file The font definition file. By default, the name is built from the family and style, in lower case with no space.		* @since 1.5		* @see SetFont()		*/		function AddFont($family, $style='', $file='') {			if(empty($family)) {				return;			}			//Add a TrueType or Type1 font			$family = strtolower($family);			if((!$this->isunicode) AND ($family == 'arial')) {				$family = 'helvetica';			}			$style=strtoupper($style);			$style=str_replace('U','',$style);			if($style == 'IB') {				$style = 'BI';			}			$fontkey = $family.$style;			// check if the font has been already added			if(isset($this->fonts[$fontkey])) {				return;			}			if($file=='') {				$file = str_replace(' ', '', $family).strtolower($style).'.php';			}			if(!file_exists($this->_getfontpath().$file)) {				// try to load the basic file without styles				$file = str_replace(' ', '', $family).'.php';			}			include($this->_getfontpath().$file);			if(!isset($name) AND !isset($fpdf_charwidths)) {				$this->Error('Could not include font definition file');			}			$i = count($this->fonts)+1;			if($this->isunicode) {				$this->fonts[$fontkey] = array('i'=>$i, 'type'=>$type, 'name'=>$name, 'desc'=>$desc, 'up'=>$up, 'ut'=>$ut, 'cw'=>$cw, 'enc'=>$enc, 'file'=>$file, 'ctg'=>$ctg);				$fpdf_charwidths[$fontkey] = $cw;			} else {				$this->fonts[$fontkey]=array('i'=>$i, 'type'=>'core', 'name'=>$this->CoreFonts[$fontkey], 'up'=>-100, 'ut'=>50, 'cw'=>$fpdf_charwidths[$fontkey]);			}			if(isset($diff) AND (!empty($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(!empty($file)) {				if((strcasecmp($type,"TrueType") == 0) OR (strcasecmp($type,"TrueTypeUnicode") == 0)) {					$this->FontFiles[$file]=array('length1'=>$originalsize);				}				else {					$this->FontFiles[$file]=array('length1'=>$size1,'length2'=>$size2);				}			}		}		/**		* Sets the font used to print character strings. It is mandatory to call this method at least once before printing text or the resulting document would not be valid.		* The font can be either a standard one or a font added via the AddFont() method. Standard fonts use Windows encoding cp1252 (Western Europe).		* The method can be called before the first page is created and the font is retained from page to page.		If you just wish to change the current font size, it is simpler to call SetFontSize().		* Note: for the standard fonts, the font metric files must be accessible. There are three possibilities for this:<ul><li>They are in the current directory (the one where the running script lies)</li><li>They are in one of the directories defined by the include_path parameter</li><li>They are in the directory defined by the FPDF_FONTPATH constant</li></ul><br />		* Example for the last case (note the trailing slash):<br />		* <pre>		* define('FPDF_FONTPATH','/home/www/font/');		* require('tcpdf.php');		*		* //Times regular 12		* $pdf->SetFont('Times');		* //Arial bold 14		* $pdf->SetFont('Arial','B',14);		* //Removes bold		* $pdf->SetFont('');		* //Times bold, italic and underlined 14		* $pdf->SetFont('Times','BIU');		* </pre><br />		* If the file corresponding to the requested font is not found, the error "Could not include font metric file" is generated.		* @param string $family Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):<ul><li>Courier (fixed-width)</li><li>Helvetica or Arial (synonymous; sans serif)</li><li>Times (serif)</li><li>Symbol (symbolic)</li><li>ZapfDingbats (symbolic)</li></ul>It is also possible to pass an empty string. In that case, the current family is retained.		* @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular</li><li>B: bold</li><li>I: italic</li><li>U: underline</li></ul>or any combination. The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats		* @param float $size Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12		* @since 1.0		* @see AddFont(), SetFontSize(), Cell(), MultiCell(), Write()		*/		function SetFont($family, $style='', $size=0) {			// save previous values			$this->prevFontFamily = $this->FontFamily;			$this->prevFontStyle = $this->FontStyle;			//Select a font; size given in points			global $fpdf_charwidths;			$family=strtolower($family);			if($family=='') {				$family=$this->FontFamily;			}			if((!$this->isunicode) AND ($family == 'arial')) {				$family = 'helvetica';			}			elseif(($family=="symbol") OR ($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') {

⌨️ 快捷键说明

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