Halaman

Rabu, 21 April 2010

FPDF Multicell: Printing automatic word wrap and border

Purpose: To print columnar style report with text descriptions lie in top area of a report.
Software: PHP + FPDF
Output:

In FPDF we use Cell method/function to print columnar data, while MultiCell is used for variable-length data to fit in a specified area.

MultiCell allows printing text with line breaks. Word or text wrapping can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other. Text can be aligned, centered or justified. The cell block can be framed and the background painted.

The example above shows a header - as what this article want to address - as a part of a Purchase Requisition form, while the same also apply for Billing or Application form, etc.

Here is a part of my class:


class PDF extends FPDF {
//my var declaration
//my public declaration

function BuatJudulObyekKerja($nomor) {
$nrowHeight=4;
$npageWidth=179;
$nwidthCol1=40;
$nwidthCol2=30;
$nwidthCol3=25;
$nColonWidth=2;

$this->SetFont('Helvetica','B',10);
$this->Cell(0, 0,'Nomor: '.$nomor,'',1,'C',0);
$this->Ln(3);
$this->SetFont('Helvetica','',8.5);
$this->Cell($npageWidth, $nrowHeight, '', 'LTR',0,'R',0);
$this->Cell($npageWidth, 2, '', '',1,'R',0);
$this->Cell($nwidthCol1, 1,'Description', 'L' ,0,'L');
$this->Cell(nColonWidth, 1,':', '' ,0,'L');

$this->SetXY(58,33);

$y=$this->GetY();
$this->MultiCell(137,$nrowHeight,$this->pan_namaobyek,'R','J');
$y1=$this->GetY();

$nrowPrinted=($y1-$y) /$nrowHeight;
$this->SetY($y);
for ($i=0; $i < $nrowPrinted; $i++) {

$this->Cell($nwidthCol1+11, $nrowHeight,'', 'L' ,1,'L');
}


$this->Cell($nwidthCol1, $nrowHeight,'Form','LT' ,0,'L');
$this->Cell($nColonWidth, $nrowHeight,':','T' ,0,'L');
$this->Cell($nwidthCol1,$nrowHeight, $this->kategori , 'T' ,0,'L');
$this->Cell($nwidthCol2, $nrowHeight,'','T',0,'L');
$this->Cell($nwidthCol3, $nrowHeight,'Doc.ID#', 'LT' ,0,'L');
$this->Cell($nColonWidth, $nrowHeight,':','T' ,0,'L');
$this->SetFont('Helvetica','B',8.5);
$this->Cell($nwidthCol1, $nrowHeight, $this->pan_pk , 'TR',1,'L');
$this->SetFont('Helvetica','',8.5);

$this->Cell($nwidthCol1, $nrowHeight,'Raised by','LT' ,0,'L');
$this->Cell($nColonWidth, $nrowHeight,':','T' ,0,'L');
$this->Cell($nwidthCol1,$nrowHeight, $this->usaha , 'T' ,0,'L');
$this->Cell($nwidthCol2, $nrowHeight,'','T',0,'L');
$this->Cell($nwidthCol3, $nrowHeight,'Reff.No', 'LT' ,0,'L');

$this->Cell($nColonWidth, $nrowHeight,':','T' ,0,'L');
$this->Cell($nwidthCol1, $nrowHeight, $this->pan_nosurat , 'TR',1,'L');
....
}

1 komentar:

  1. Boleh saya minta script lengkapnya boz, saya sedang belajar buat report namun banyak kesulitan

    BalasHapus