繁体   English   中英

FPDF与图像和单元格对齐

[英]FPDF align with Image and Cell

我正在尝试在PHP中由FPDF生成的PDF文件中进行以下布局。

--------------------------------------------------
|                        |       Text1           |
|  IMAGE                 |       Text2           |
|                        |       Text3           | 
--------------------------------------------------

但是我现在还不知道该怎么做。

这是我正在使用的代码

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);

这是我现在生成的结果

到现在为止

如果将最后两个单元格的宽度更改为100,它将如下所示:

如果像元宽度设置为100

几乎是我想要的,单元格必须与右侧对齐。 我怎样才能做到这一点?

我自己找到了答案

您可以将pdf设置为X值,并确定X轴上的位置。

$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();

值得一提的是,在每次写入单元格X之后,都会从Cell()函数中分配一个新值。 因此,您需要在创建新Cell之前先设置SetX()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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