如何在 fpdf - PHP 上添加空格或制表符? [ fpdf 上的 function cell() 无法工作 ]

问题描述 投票:0回答:2

您知道如何在 fpdf 上添加空格或制表符吗?我使用了表格和更改单元格功能,但仍然无法正常工作。

我想在“jakarta”之外添加“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; 


?>

非常感谢您的帮助

php pdf tabs space fpdf
2个回答
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
投票

将单元格的宽度更改得更长,就像这样

$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.
© www.soinside.com 2019 - 2024. All rights reserved.