更改TCPDF标题字符串浮动

问题描述:

你好*人,我需要TCPDF的帮助,我不知道如何使标题字符串浮动正确。贝娄有我的剧本的代码。我想离开标题标识,但标题字符串是问题。那么我怎么能改变它的权利?更改TCPDF标题字符串浮动

$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $AppUI->_('Project Completed Task Report'), PDF_HEADER_STRING); 

要创建custome头部,则需要扩展TCPDF类并覆盖Header()功能: 然后在功能有一个Cell()方法,你需要修改其属性之一:

假设

$this->Cell(0, 15, '<< Header TITLE >>', 0, false, 'C', 0, '', 0, false, 'M', 'M'); 

'C'表示CENTER(默认),您需要更改为'R'才达到浮动权

$this->Cell(0, 15, '<< Header TITLE >>', 0, false, 'R', 0, '', 0, false, 'M', 'M'); 

这是我简化了例子:(根据您的TCPDF文件夹所属的位置改变require_once()值)

<?php 
require_once('D:\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.'logo_example.jpg'; 
     $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 to right allignment 
     $this->Cell(0, 15, '<< Header TITLE >>', 0, false, 'R', 0, '', 0, false, 'M', 'M'); 
    } 
} 

// 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 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 font 
$pdf->SetFont('times', 'BI', 12); 

// add a page 
$pdf->AddPage(); 

// set some text to print 
$txt = <<<EOD 
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); 

$pdf->Output('example.pdf', 'I'); 

要获得更多信息,请http://www.tcpdf.org/examples.php