简体   繁体   中英

FPDF align with Image and Cell

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:

如果像元宽度设置为100

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM