2015-06-26 23 views
1

你知道如何在fpdf上添加空格或製表符嗎?我用表和改變單元格功能,但仍然無法正常工作。如何在fpdf上添加空格或製表符 - PHP? [函數單元()fpdf不能工作]

我想添加「keperluan」除了「雅加達」,如下圖所示。

enter image description here

這裏是源代碼:

<?php 

require('../fpdf17/fpdf.php'); 
require('../koneksi.php'); 


class PDF extends FPDF 
{ 

function LoadDataFromSQL($sql) 
{ 
    $hasil=mysql_query($sql) or die(mysql_error()); 

    $data = array(); 
    while($rows=mysql_fetch_array($hasil)){ 
     $data[] = $rows; 

} 
    return $data; 
} 


// Colored table 
function FancyTable($header, $data) 
{ 
    // Colors, line width and bold font 
    $this->SetFillColor(255,255,255); 
    $this->SetTextColor(0); 
    $this->SetDrawColor(0,0,0); 
    $this->SetLineWidth(.3); 
    $this->SetFont('','B'); 

    // Header 
    $w = array(65,65,30,30); 
    for($i=0;$i<count($header);$i++) 
     $this->Cell($w[$i],7,$header[$i],0,0,'C',true); 

    $this->Ln(); 
    // Color and font restoration 
    $this->SetFillColor(224,235,255); 
    $this->SetTextColor(0); 
    $this->SetFont(''); 
    // Data 
    $fill = false; 



    foreach($data as $row) 
    { 
     /* $this->Cell($w[0],6,'1. Uang Harian Pegawai','LR',0,'L',$fill); 
     $this->Cell($w[1],6,$row[uangharian],'LR',0,'L',$fill); 
     $this->Cell($w[2],6,$row[totaluangharian],'LR',0,'L',$fill); 
     $this->Cell($w[3],6,' ','LR',0,'C',$fill); 
     $this->Ln(); 
     $this->Cell($w[0],6,'2. Uang Tunjangan PDLN','LR',0,'L',$fill); 
     $this->Cell($w[1],6,$row[tunjangan],'LR',0,'L',$fill); 
     $this->Cell($w[2],6,$row[totatunjangan],'LR',0,'L',$fill); 
     $this->Cell($w[3],6,' ','LR',0,'C',$fill); 
     $this->Ln(); 
     $this->Cell($w[0],6,'3. Uang Taksi Bandara LN Pegawai','LR',0,'L',$fill); 
     $this->Cell($w[1],6,$row[taksiln],'LR',0,'L',$fill); 
     $this->Cell($w[2],6,$row[totaltaksiln],'LR',0,'L',$fill); 
     $this->Cell($w[3],6,' ','LR',0,'C',$fill); 
     $this->Ln(); 
     $this->Cell($w[0],6,'','LR',0,'C',$fill); 
     $this->Cell($w[1],6,'Sub Total USD','LR',0,'R',$fill); 
     $this->Cell($w[2],6,$row[totalusd],'LR',0,'L',$fill); 
     $this->Cell($w[3],6,' ','LR',0,'C',$fill); 
     $this->Ln(); 

     $this->Cell($w[0],6,'5. Uang Taksi Bandara DN','LR',0,'L',$fill); 
     $this->Cell($w[1],6,$row[taksidn],'LR',0,'L',$fill); 
     $this->Cell($w[2],6,'','LR',0,'C',$fill); 
     $this->Cell($w[3],6,$row[totaltaksidn],'LR',0,'L',$fill); 
     $this->Ln(); 
     $this->Cell($w[0],6,'','LR',0,'L',$fill); 
     $this->Cell($w[1],6,'Sub Total Rupiah','LR',0,'R',$fill); 
     $this->Cell($w[2],6,'','LR',0,'C',$fill); 
     $this->Cell($w[3],6,$row[totalrupiah],'LR',0,'L',$fill); 
     $this->Ln(); 
     $this->Cell($w[0],6,'4. Airport Tax Pegawai','LR',0,'L',$fill); 
     $this->Cell($w[1],6,$row[airporttax].' Rupiah','LR',0,'L',$fill); 
     $this->Cell($w[2],6,'','LR',0,'C',$fill); 
     $this->Cell($w[3],6,$row[airporttax].' Rupiah' ,'LR',0,'L',$fill); 
     $this->Ln(); 
     $fill = !$fill; */ 

    } 
    // Closing line 
    $this->Cell(array_sum($w),0,'','T'); 
} 
function FancyTables($headers, $data) 
{ 
    // Colors, line width and bold font 
    $this->SetFillColor(255,255,255); 
    $this->SetTextColor(0); 
    $this->SetDrawColor(255,255,255); 
    $this->SetLineWidth(.3); 
    $this->SetFont('','',11); 

    // Header 
    $w = array(35,40,40,40, 35); 

    for($i=0;$i<count($headers);$i++) 
     $this->Cell($w[$i],7,$headers[$i],1,0,'C',true); 
    $this->Ln(); 
    // Color and font restoration 
    $this->SetFillColor(0,0,0); 
    $this->SetTextColor(0); 
    $this->SetFont('','',7); 
    // Data 
    $fill = false; 

    foreach($data as $row) 
    { 
     $this->Cell($w[0],6,'','LR',0,'C'); 
     $this->Cell($w[1],6,' ','LR',0,'C'); 
     $this->Cell($w[2],6,' ','LR',0,'C'); 
     $this->Cell($w[3],6,' ','LR',0,'C'); 
     $this->Cell($w[4],6,' ','LR',0,'C'); 
     $this->Ln(); 
     $this->Ln(); 
     $this->Ln(); 
     $this->Cell($w[0],6,'______________________','LR',0,'C',$fill); 
     $this->Cell($w[1],6,'_________________________','LR',0,'C',$fill); 
     $this->Cell($w[2],6,'_________________________','LR',0,'C',$fill); 
     $this->Cell($w[3],6,'_________________________','LR',0,'C',$fill); 
     $this->Cell($w[4],6,'______________________','LR',0,'C',$fill); 
     $this->Ln(); 
     $this->Cell($w[0],6,$row['pegawai_EmployeeName'],'LR',0,'C',$fill); 
     $this->Cell($w[1],6,' ','LR',0,'C',$fill); 
     $this->Cell($w[2],6,' ','LR',0,'C',$fill); 
     $this->Cell($w[3],6,' ','LR',0,'C',$fill); 
     $this->Cell($w[4],6,' ','LR',0,'C',$fill); 
     $this->Ln(); 
     $fill = !$fill; 

    } 
    // Closing line 
    $this->Cell(array_sum($w),0,'','T'); 
} 
} 





$pdf = new PDF(); 
// Column headings 
$pdf->addPage(); 
$pdf->setAutoPageBreak(true); 

$pdf->setFont('Times','B',14); 
$pdf->text(50,8,'FORMULIR PERMINTAAN KENDARAAN'); 

$pdf->setFont('Times','B',6); 
$pdf->FancyTable($header,$data); 



$pdf->Ln(50); 


$headers = array('Pemohon,', 'KaDept. Pemohon,','KaBag Transport,', 'KaDept Transport,','Pool,'); 

$id=$_GET['id']; 
$nip = $_GET['nip']; 

$sql=mysql_query("SELECT * FROM formulir where RequestNumber = '$id' ") or die(mysql_error()); 
$data=mysql_fetch_array($sql); 

    $tanggalberangkat = $data['tglberangkat']; 
     $berangkat = date('d F Y', strtotime($tanggalberangkat)); 

     $tanggalpulang = $data['tglpulang']; 
     $pulang = date('d F Y', strtotime($tanggalpulang)); 



$query3 = "SELECT * FROM formulir where RequestNumber = '$id'"; 
     $rowSet3 = mysql_query($query3); 
     $row3 = mysql_fetch_array($rowSet3); 



$pdf->setFont('Times','B',11); 

$pdf->Cell(6,10,'Request Number',0,0,'L'); 
$pdf->setFont('Times','',11); 
$pdf->Cell(6,10,'         : '.$data['RequestNumber'],0,1, 'L'); 



$pdf->setFont('Times','B',11); 
$pdf->Cell(6,0.5,'Employee',0,0,'L'); 
$pdf->setFont('Times','',11); 
$pdf->Cell(6,0.5,'         : '.$data['pegawai_EmployeeName'],0,1, 'L'); 

$pdf->setFont('Times','B',11); 
$pdf->Cell(6,10,'NIK',0,0,'L'); 
$pdf->setFont('Times','',11); 
$pdf->Cell(6,10,'         : '.$data['pegawai_EmployeeID'],0,1, 'L'); 

$pdf->setFont('Times','B',11); 
$pdf->Cell(6,0.5,'Bagian',0,0,'L'); 
$pdf->setFont('Times','',11); 
$pdf->Cell(6,0.5,'         : '.$data['jabatan'],0,1, 'L'); 

$pdf->setFont('Times','B',11); 
$pdf->Cell(6,10,'Departemen',0,0,'L'); 
$pdf->setFont('Times','',11); 
$pdf->Cell(6,10,'         : '.$data['Departemen'],0,1, 'L'); 

$pdf->setFont('Times','B',11); 
$pdf->Cell(6,0.5,'Dipergunakan',0,0); 
$pdf->setFont('Times','',11); 
$pdf->Cell(6,0.5,'         : '.$berangkat,0,0); 
$pdf->Cell(6,0.5,'              Pukul : '.$data['jamkeberangkatan'],0,1,'L'); 

$pdf->setFont('Times','B',11); 
$pdf->Cell(6,10,'Jenis Kendaraan',0,0,'L'); 
$pdf->setFont('Times','',11); 
$pdf->Cell(6,10,'         : '.$data['tujuan'],0,1, 'L'); 

$pdf->setFont('Times','B',11); 
$pdf->Cell(6,0.5,'Tujuan',0,0,'L'); 
$pdf->setFont('Times','',11); 
$pdf->Cell(6,0.5,'         : '.$data['tujuan'],0,1, 'L'); 

$pdf->setFont('Times','B',11); 
$pdf->Cell(6,10,'Keperluan',0,0,'L'); 
$pdf->setFont('Times','',11); 
$pdf->Cell(6,10,'         : '.$data['keperluan'],0,1, 'L'); 

$pdf->setFont('Times','B',11); 
$pdf->Cell(6,0.5,'Catatan',0,0,'L'); 
$pdf->setFont('Times','',11); 
$pdf->Cell(6,0.5,'         : '.$data['catatan'],0,1, 'L'); 



$query = "SELECT * FROM formulir where RequestNumber = '$id' ";     

$data = $pdf->LoadDataFromSQL($query); 
$pdf->Ln(20); 
$pdf->SetFont('Times','',12); 
$pdf->FancyTables($headers,$data); 

$pdf->Output(); 
$pdf->Ln; 


?> 

非常感謝你的幫助

回答

0

只是改變這一行

$pdf->Cell(6,0.5,'         : '.$data['tujuan'],0,1, 'L'); 

是這樣

$pdf->Cell(6,0.5,'         : '.$data['tujuan'],0,0, 'L'); 

,或者你可以添加空白單元格之前斷行單元格...記得$pdf->cell($width,$height,0,1,'L')1意味着突破並進入下一行

+0

但仍不能正常工作,您有其他解決方法嗎? – TARA

+0

我已經編輯我的回答 –

+0

是的,但我仍然困惑。我已經發布了我的完整源代碼,謝謝。 – TARA

0

更改單元格的長寬度,這樣

$pdf->Cell(15,0.5,': '.$data['tujuan'],0,0, 'L'); 

//這裏

$pdf->Cell(6,0.5,': '.$data['i want to add data in this area'],0,1, 'L'); 

//

添加數據
$pdf->Cell(15,0.5,': '.$data['keperluan'],0,1, 'L'); 

$pdf->Cell(15,0.5,': '.$data['catatan'],0,1, 'L'); 
. 
. 
etc.