I'm trying to do the following layout in an PDF file generated by FPDF in PHP.
--------------------------------------------------
| | Text1 |
| IMAGE | Text2 |
| | Text3 |
--------------------------------------------------
But I couldn't figure out how to do it by now.
This is the code I'm using
public function floatingImage($imgPath, $height) {
list($w, $h) = getimagesize($imgPath);
$ratio = $w / $h;
$imgWidth = $height * $ratio;
$this->Image($imgPath, $this->GetX(), $this->GetY(), 140, 100);
$this->x += $imgWidth;
}
/* Logbuch is our extension from FPDI, but there's nothing changed
* only a custom header, footer and the floatingImage and loadMapImage function are part of it
*/
$pdf = new logbuch();
// Frontpage
$pdf->AddPage();
$mapImage = $pdf->loadMapImage();
$pdf->setJPEGQuality(75);
$x = 15; $y = 21; $w = 100;
$pdf->floatingImage($mapImage, 100, 100);
$pdf->SetFillColor(154,222,229);
$pdf->Cell(0,0,"Test",0,0,'R',true);
$pdf->Ln();
$pdf->Cell(100,0,"Test",0,0,'R',true);
$pdf->Ln();
$pdf->Cell(100,0,"Test",0,0,'R',true);
This is the result I'm generating by now
If I change the width of the last two cells to 100 it will look like this:
This is nearly what I want, the cells just must align to the right side. How can I do this?
I found the answer myself
You can set an X
value to the pdf with determines the position on the X axis.
$pdf->Cell(0,0,"Test",0,0,'R',true);
$pdf->Ln();
$pdf->SetX(100); //The next cell will be set 100 units to the right
$pdf->Cell(100,0,"Test",0,0,'R',true);
$pdf->Ln();
Importend to mention is that after every wrote Cell X
will be asigned a new value from the Cell()
function. So you need to SetX()
before creating a new Cell!