Search code examples
phpfpdf

new line in FPDF


I am using PDO for connection database. this is output from my code: enter image description here

I want all cell same line, not change line. i try search in my code to delete if any code with ln(). but not find it. i don't know why it not show beside.

this is my code:

$stmt->execute(array('idFotoJaminan'=>$idFotoJaminan));
$result = $stmt->fetchALL(PDO::FETCH_ASSOC);


//$pdf->Cell(40,10,'LAMPIRAN FOTO\nJAMINAN',1,1,'C');
$pdf->Multicell(40,4,"LAMPIRAN FOTO\nJAMINAN",1,"C");

foreach($result as $row) {
$pdf->Multicell(80,4,'Debitur : '. $row['debitur'],1); 
//$pdf->Ln();
//$pdf->Cell(0,5,'L NAME:', $row['lname']);
$pdf->Cell(0,5,'L NAME:'. $row['debitur'], 0, 0, 'L'); 
//$pdf->Ln();
}
$pdf->Output();

Solution

  • Your cells are with different width. First Multicell is 40 second one inside loop is 80

    $pdf->Multicell(40,4,"LAMPIRAN FOTO\nJAMINAN",1,"C");
    ...
    $pdf->Multicell(80,4,'Debitur : '. $row['debitur'],1);
    

    Try to make them equal

    $pdf->Multicell(80,4,"LAMPIRAN FOTO\nJAMINAN",1,"C");
    ...
    $pdf->Multicell(80,4,'Debitur : '. $row['debitur'],1);
    

    Then if you don't want LAMPIRAN FOTO\nJAMINAN to go on new line remove \n from it.

    Here is good example with table and Multicells: