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

📄 tcpdf.php

📁 简介:一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 5 页
字号:
				$style='BI';			}			if($size==0) {				$size=$this->FontSizePt;			}			// try to add font (if not already added)			if($this->isunicode) {				$this->AddFont($family, $style);			}						//Test if font is already selected			if(($this->FontFamily == $family) AND ($this->FontStyle == $style) AND ($this->FontSizePt == $size)) {				return;			}						$fontkey = $family.$style;			//if(!isset($this->fonts[$fontkey]) AND isset($this->fonts[$family])) {			//	$style='';			//}			//Test if used for the first time			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!='symbol') AND ($family!='zapfdingbats')) {							$file .= strtolower($style);						}						if(!file_exists($this->_getfontpath().$file.'.php')) {							// try to load the basic file without styles							$file = $family;							$fontkey = $family;						}						include($this->_getfontpath().$file.'.php');						if (($this->isunicode AND !isset($ctg)) OR ((!$this->isunicode) AND (!isset($fpdf_charwidths[$fontkey]))) ) {							$this->Error("Could not include font metric file [".$fontkey."]: ".$this->_getfontpath().$file.".php");						}					}					$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]);					}				}				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));			}		}		/**		* Defines the size of the current font.		* @param float $size The size (in points)		* @since 1.0		* @see SetFont()		*/		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));			}		}		/**		* Creates a new internal link and returns its identifier. An internal link is a clickable area which directs to another place within the document.<br />		* The identifier can then be passed to Cell(), Write(), Image() or Link(). The destination is defined with SetLink().		* @since 1.5		* @see Cell(), Write(), Image(), Link(), SetLink()		*/		function AddLink() {			//Create a new internal link			$n=count($this->links)+1;			$this->links[$n]=array(0,0);			return $n;		}		/**		* Defines the page and position a link points to		* @param int $link The link identifier returned by AddLink()		* @param float $y Ordinate of target position; -1 indicates the current position. The default value is 0 (top of page)		* @param int $page Number of target page; -1 indicates the current page. This is the default value		* @since 1.5		* @see AddLink()		*/		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);		}		/**		* Puts a link on a rectangular area of the page. Text or image links are generally put via Cell(), Write() or Image(), but this method can be useful for instance to define a clickable area inside an image.		* @param float $x Abscissa of the upper-left corner of the rectangle		* @param float $y Ordinate of the upper-left corner of the rectangle		* @param float $w Width of the rectangle		* @param float $h Height of the rectangle		* @param mixed $link URL or identifier returned by AddLink()		* @since 1.5		* @see AddLink(), Cell(), Write(), Image()		*/		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);		}		/**		* Prints a character string. The origin is on the left of the first charcter, on the baseline. This method allows to place a string precisely on the page, but it is usually easier to use Cell(), MultiCell() or Write() which are the standard methods to print text.		* @param float $x Abscissa of the origin		* @param float $y Ordinate of the origin		* @param string $txt String to print		* @since 1.0		* @see SetFont(), SetTextColor(), Cell(), MultiCell(), Write()		*/		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,$txt);			}			if($this->ColorFlag) {				$s='q '.$this->TextColor.' '.$s.' Q';			}			$this->_out($s);		}		/**		* Whenever a page break condition is met, the method is called, and the break is issued or not depending on the returned value. The default implementation returns a value according to the mode selected by SetAutoPageBreak().<br />		* This method is called automatically and should not be called directly by the application.<br />		* <b>Example:</b><br />		* The method is overriden in an inherited class in order to obtain a 3 column layout:<br />		* <pre>		* class PDF extends TCPDF {		* 	var $col=0;		*		* 	function SetCol($col) {		* 		//Move position to a column		* 		$this->col=$col;		* 		$x=10+$col*65;		* 		$this->SetLeftMargin($x);		* 		$this->SetX($x);		* 	}		*		* 	function AcceptPageBreak() {		* 		if($this->col<2) {		* 			//Go to next column		* 			$this->SetCol($this->col+1);		* 			$this->SetY(10);		* 			return false;		* 		}		* 		else {		* 			//Go back to first column and issue page break		* 			$this->SetCol(0);		* 			return true;		* 		}		* 	}		* }		*		* $pdf=new PDF();		* $pdf->Open();		* $pdf->AddPage();		* $pdf->SetFont('Arial','',12);		* for($i=1;$i<=300;$i++) {		*     $pdf->Cell(0,5,"Line $i",0,1);		* }		* $pdf->Output();		* </pre>		* @return boolean		* @since 1.4		* @see SetAutoPageBreak()		*/		function AcceptPageBreak() {			//Accept automatic page break or not			return $this->AutoPageBreak;		}		/**		* Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text.<br />		* If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.		* @param float $w Cell width. If 0, the cell extends up to the right margin.		* @param float $h Cell height. Default value: 0.		* @param string $txt String to print. Default value: empty string.		* @param mixed $border Indicates if borders must be drawn around the cell. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>		* @param int $ln Indicates where the current position should go after the call. Possible values are:<ul><li>0: to the right</li><li>1: to the beginning of the next line</li><li>2: below</li></ul>		Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.		* @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align (default value)</li><li>C: center</li><li>R: right align</li></ul>		* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.		* @param mixed $link URL or identifier returned by AddLink().		* @since 1.0		* @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), AddLink(), Ln(), MultiCell(), Write(), SetAutoPageBreak()		*/		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 empty($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(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 != '') {				$width = $this->GetStringWidth($txt);				if($align == 'R') {					$dx = $w - $this->cMargin - $width;				}				elseif($align=='C') {					$dx = ($w - $width)/2;				}				else {					$dx = $this->cMargin;				}				if($this->ColorFlag) {					$s .= 'q '.$this->TextColor.' ';				}				$txt2 = $this->_escapetext($txt);				$s.=sprintf('BT %.2f %.2f Td (%s) Tj ET', ($this->x + $dx) * $k, ($this->h - ($this->y + 0.5 * $h + 0.3 * $this->FontSize)) * $k, $txt2);				if($this->underline) {					$s.=' '.$this->_dounderline($this->x + $dx, $this->y + 0.5 * $h + 0.3 * $this->FontSize, $txt);				}				if($this->ColorFlag) {					$s.=' Q';				}				if($link) {					$this->Link($this->x + $dx, $this->y + 0.5 * $h - 0.5 * $this->FontSize, $width, $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;			}		}		/**		* This method allows printing text with line breaks. They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other.<br />		* Text can be aligned, centered or justified. The cell block can be framed and the background painted.		* @param float $w Width of cells. If 0, they extend up to the right margin of the page.		* @param float $h Height of cells.		* @param string $txt String to print		* @param mixed $border Indicates if borders must be drawn around the cell block. The value can be either a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul>		* @param string $align Allows to center or align the text. Possible values are:<ul><li>L or empty string: left align</li><li>C: center</li><li>R: right align</li><li>J: justification (default value)</li></ul>		* @param int $fill Indicates if the cell background must be painted (1) or transparent (0). Default value: 0.		* @since 1.3		* @see SetFont(), SetDrawColor(), SetFillColor(), SetTextColor(), SetLineWidth(), Cell(), Write(), SetAutoPageBreak()		*/		function MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0) {			//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);			$s = str_replace("\r", '', $txt); // remove carriage returns			$nb = strlen($s);			$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(preg_match("/[\n]/u", $c)) {					//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 and $nl==2) {						$b = $b2;					}					continue;				}				if(preg_match("/[ ]/u", $c)) {					$sep = $i;					$ls = $l;					$ns++;				}				$l = $this->GetStringWidth(substr($s, $j, $i-$j));				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)/($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 AND ($nl==2)) {						$b=$b2;					}				}				else {					$i++;				}			}			//Last chunk			if($this->ws>0) {				$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;		}		/**		* This method prints text from the current position. When the right margin is reached (or the \n character is met) a line break occurs and text continues from the left mar

⌨️ 快捷键说明

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