2015-07-21 65 views
0

你好stackoverflow人,我需要TCPDF的幫助,我不知道如何使標題字符串浮動正確。貝婁有我的劇本的代碼。我想離開標題標識,但標題字符串是問題。那麼我怎麼能改變它的權利?更改TCPDF標題字符串浮動

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

回答

1

要創建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