📄 tcpdf.php
字号:
* $this->SetY(-15); * //Select Arial italic 8 * $this->SetFont('vera','I',8); * //Print current and total page numbers * $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); * } * } * $pdf=new PDF(); * $pdf->AliasNbPages(); * </pre> * @param string $alias The alias. Default value: {nb}. * @since 1.4 * @see PageNo(), Footer() */ function AliasNbPages($alias='{nb}') { //Define an alias for total number of pages $this->AliasNbPages = $this->_escapetext($alias); } /** * This method is automatically called in case of fatal error; it simply outputs the message and halts the execution. An inherited class may override it to customize the error handling but should always halt the script, or the resulting document would probably be invalid. * 2004-06-11 :: Nicola Asuni : changed bold tag with strong * @param string $msg The error message * @since 1.0 */ function Error($msg) { //Fatal error die('<strong>TCPDF error: </strong>'.$msg); } /** * This method begins the generation of the PDF document. It is not necessary to call it explicitly because AddPage() does it automatically. * Note: no page is created by this method * @since 1.0 * @see AddPage(), Close() */ function Open() { //Begin document $this->state=1; } /** * Terminates the PDF document. It is not necessary to call this method explicitly because Output() does it automatically. If the document contains no page, AddPage() is called to prevent from getting an invalid document. * @since 1.0 * @see Open(), Output() */ 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(); } /** * Reset pointer to the last document page. * @since 2.0.000 (2008-01-04) * @see setPage(), getPage(), getNumPages() */ function lastPage() { $this->page = count($this->pages); } /** * Move pointer to the apecified document page. * @param int $pnum page number * @since 2.1.000 (2008-01-07) * @see getPage(), lastpage(), getNumPages() */ function setPage($pnum) { if(($pnum > 0) AND ($pnum <= count($this->pages))) { $this->page = $pnum; } } /** * Get current document page number. * @return int page number * @since 2.1.000 (2008-01-07) * @see setPage(), lastpage(), getNumPages() */ function getPage() { return $this->page; } /** * Get the total number of insered pages. * @return int number of pages * @since 2.1.000 (2008-01-07) * @see setPage(), getPage(), lastpage() */ function getNumPages() { return count($this->pages); } /** * Adds a new page to the document. If a page is already present, the Footer() method is called first to output the footer. Then the page is added, the current position set to the top-left corner according to the left and top margins, and Header() is called to display the header. * The font which was set before calling is automatically restored. There is no need to call SetFont() again if you want to continue with the same font. The same is true for colors and line width. * The origin of the coordinate system is at the top-left corner and increasing ordinates go downwards. * @param string $orientation Page orientation. Possible values are (case insensitive):<ul><li>P or Portrait</li><li>L or Landscape</li></ul> The default value is the one passed to the constructor. * @since 1.0 * @see TCPDF(), Header(), Footer(), SetMargins() */ function AddPage($orientation='') { if (count($this->pages) > $this->page) { // this page has been already added $this->page++; $this->y = $this->tMargin; return; } //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; } /** * Set header data. * @param string $ln header image logo * @param string $lw header image logo width in mm * @param string $ht string to print as title on document header * @param string $hs string to print on document header */ function setHeaderData($ln="", $lw=0, $ht="", $hs="") { $this->header_logo = $ln; $this->header_logo_width = $lw; $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; } /** * Set a flag to print page header. * @param boolean $val set to true to print the page header (default), false otherwise. */ function setPrintHeader($val=true) { $this->print_header = $val; } /** * Set a flag to print page footer. * @param boolean $value set to true to print the page footer (default), false otherwise. */ function setPrintFooter($val=true) { $this->print_footer = $val; } /** * 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; } // reset original header margins $this->rMargin = $this->original_rMargin; $this->lMargin = $this->original_lMargin; // save current font values $font_family = $this->FontFamily; $font_style = $this->FontStyle; $font_size = $this->FontSizePt; //set current position if ($this->rtl) { $this->SetXY($this->original_rMargin, $this->header_margin); } else { $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->GetX(), $this->header_margin, $this->header_logo_width); } else { $this->img_rb_x = $this->GetX(); $this->img_rb_y = $this->GetY(); } $cell_height = round((K_CELL_HEIGHT_RATIO * $this->header_font[2]) / $this->k, 2); // set starting margin for text data cell if ($this->rtl) { $header_x = $this->original_rMargin + ($this->header_logo_width * 1.1); } else { $header_x = $this->original_lMargin + ($this->header_logo_width * 1.1); } // 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, ''); // 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, '', 0, 1, 0, 0, true, 0); // print an ending header line //set style for cell border $prevlinewidth = $this->GetLineWidth(); $line_width = 0.3; $this->SetLineWidth($line_width); $this->SetDrawColor(0, 0, 0); $this->SetY(1 + max($this->img_rb_y, $this->GetY())); if ($this->rtl) { $this->SetX($this->original_rMargin); } else { $this->SetX($this->original_lMargin); } $this->Cell(0, 0, '', 'T', 0, 'C'); $this->SetLineWidth($prevlinewidth); //restore position if ($this->rtl) { $this->SetXY($this->original_rMargin, $this->tMargin); } else { $this->SetXY($this->original_lMargin, $this->tMargin); } // restore font values $this->SetFont($font_family, $font_style, $font_size); } } /** * 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; } // reset original header margins $this->rMargin = $this->original_rMargin; $this->lMargin = $this->original_lMargin; // save current font values $font_family = $this->FontFamily; $font_style = $this->FontStyle; $font_size = $this->FontSizePt; //set font $this->SetFont($this->footer_font[0], $this->footer_font[1] , $this->footer_font[2]); //set style for cell border $prevlinewidth = $this->GetLineWidth(); $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 if ($this->rtl) { $this->SetXY($this->original_rMargin, $footer_y); } else { $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)/3); //max width $this->writeBarcode($this->GetX(), $footer_y + $line_width, $barcode_width, $footer_height - $line_width, "C128B", false, false, 2, $this->barcode); } $pagenumtxt = $this->l['w_page']." ".$this->PageNo().' / {nb}'; $this->SetY($footer_y); //Print page number if ($this->rtl) { $this->SetX($this->original_rMargin); $this->Cell(0, $footer_height, $pagenumtxt, 'T', 0, 'L'); } else { $this->SetX($this->original_lMargin); $this->Cell(0, $footer_height, $pagenumtxt, 'T', 0, 'R'); } // restore line width $this->SetLineWidth($prevlinewidth); // restore font values $this->SetFont($font_family, $font_style, $font_size); } } /** * 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); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -