一、TCPDF 背景圖片透明度 php
參考:https://bbs.csdn.net/topics/392364981tcp
效果:ide
二、畫一條線:測試
2.1方法解說 ui
/*畫一條線:this
x1:線條起點x座標spa
y1:線條起點y座標.net
x2:線條終點x座標code
y2:線條終點y座標orm
style:SetLineStyle的效果同樣
*/
// $pdf->Line($x1, $y1, $x2, $y2, $style=array());
2.2方法使用:
/*線的顏色*/ $this->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => '0', 'color' => array(220, 20,60))); /*畫一條線*/ $this->Line(1, 100, 100, 1, $style=array()); /*加入一條下劃線 下劃線顏色默認爲黑色,用此方法【SetLineStyle()】能夠自定義線的顏色 */ $this->Cell(180, 0, '', 1, 0, 'C', 0, '', 0, true);
2.3效果:
3.自定義頁眉頁腳:
/* * * */ function zidingyi_yemei(){ //============================================================+ // File name : example_003.php // Begin : 2008-03-04 // Last Update : 2013-05-14 // // Description : Example 003 for TCPDF class // Custom Header and Footer // // Author: Nicola Asuni // // (c) Copyright: // Nicola Asuni // Tecnick.com LTD // www.tecnick.com // info@tecnick.com //============================================================+ /** * Creates an example PDF TEST document using TCPDF * @package com.tecnick.tcpdf * @abstract TCPDF - Example: Custom Header and Footer * @author Nicola Asuni * @since 2008-03-04 */ // Include the main TCPDF library (search for installation path). require_once('ThinkPHP/Library/Vendor/tcpdf/tcpdf.php'); // Extend the TCPDF class to create custom Header and Footer class MYPDF extends TCPDF { //Page header /*public function Header() { // Logo $image_file = K_PATH_IMAGES.'bl_logo.png'; $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false); // Set font $this->SetFont('helvetica', 'B', 20); // Title $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M'); } // Page footer public function Footer() { // Position at 15 mm from bottom $this->SetY(-15); // Set font $this->SetFont('helvetica', 'I', 8); // Page number $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M'); }*/ //Page header 自定義頁眉 public function Header() { $this->SetFont('stsongstdlight', '', 10); $this->SetHeaderData('', '', ''.' 001', '', array(0,64,255), array(0,64,128)); // Title $this->SetY(1); $image_file = K_PATH_IMAGES.'bl_logo.png'; $this->SetY(1); $this->Image($image_file, 15, 3.2, 5, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false); $this->SetY(3.7); $left_text = '<p style="text-indent: 20px; color: #00489A; font-weight: bold;">山東保藍環保工程有限公司</p>'; //$this->Write(0, $left_text, '', 0, 'L', true, 0, false, false, 0); $this->writeHTML($left_text, 1, false, true, false, 'L'); $this->SetY(3.7); $right_text = '<p style="color: #00489A; font-weight: bold;">技術方案</p>'; $this->writeHTML($right_text, 1, false, true, false, 'R'); /*$this->Cell(0, 10, ' 山東保藍環保工程有限公司', 0, 0, 'L'); $this->Cell(0, 10, '技術方案', 0, 0, 'R');*/ //$this->SetX(1); $this->SetY(9); /*頁眉下劃線顏色*/ $this->SetLineStyle(array('width' => 0, 'cap' => 'butt', 'join' => 'miter', 'dash' => '0', 'color' => array(128,128,128))); /*靠左面的距離,左上角的距離 ,長度,右上角的距離*/ $this->Line(14, 8.6, 196, 8.6, $style=array()); $this->SetY(19); /*頁眉下劃線*/ $this->Cell(180, 0, '', 1, 0, 'C', 0, '', 0, true); } // Page footer 自定義頁腳 public function Footer() { // Position at 15 mm from bottom $this->SetY(-15); // Set font $this->SetFont('helvetica', 'I', 8); // Page number $this->Cell(0, 10, ' '.$this->getAliasNumPage().' / '.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M'); } /*function Header() //設定頁眉 { $this->SetFont('stsongstdlight','',10); $this->Write(10,'IPv6協議一致性測試報告','',false,'C'); $this->Ln(20); } function Footer() //設定頁腳 { $this->SetY(-15); $this->SetFont('stsongstdlight','',10); $this->Cell(0,10,'第'.$this->PageNo().'頁',0,0,'R'); }*/ } // create new PDF document $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Nicola Asuni'); $pdf->SetTitle('TCPDF Example 003'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); // set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); // set some language-dependent strings (optional) if (@file_exists(dirname(__FILE__).'/lang/eng.php')) { require_once(dirname(__FILE__).'/lang/eng.php'); $pdf->setLanguageArray($l); } // --------------------------------------------------------- // set font $pdf->SetFont('times', 'BI', 12); // add a page $pdf->AddPage(); // set some text to print $txt = <<<EOD TCPDF Example 003 Custom page header and footer are defined by extending the TCPDF class and overriding the Header() and Footer() methods. EOD; // print a block of text using Write() $pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0); // --------------------------------------------------------- //Close and output PDF document $pdf->Output('example_003.pdf', 'I'); //============================================================+ // END OF FILE //============================================================+ }
效果: