使用 FPD 在 PDF 中定位单元格


positioning the cell in pdf using fpdf

我正在尝试根据用户在表单中输入的数据制作pdf。我正在使用 fpdf 来做到这一点。到目前为止,我有这样的东西将数据添加到pdf中 -

$pdf->Cell(40,200,'Descritpion');
$pdf->Cell(150,200,$_POST['element_1']);
$pdf->Cell(40,400,'Descritpion2');
$pdf->Cell(150,400,$_POST['element_2']);

这确实有效,但我想知道的是如何在不指定位置的情况下将它们添加到 pdf 中。正如您在上面的代码中看到的那样,我提到了数据应该在 pdf 中的位置,但我想知道是否有办法在不指定它们的情况下做到这一点。即描述 1 和 element_1 应该在前几行,描述 2 应该从element_1结束的地方开始。

"正如您在上面的代码中看到的那样,我提到了数据应该在pdf中的位置"这是不正确的。 宽度 40 和高度 400 是要创建的单元格的宽度和高度,而不是 PDF 上的位置。如果要在pdf上设置单元格的位置,则需要在创建单元格之前使用SetX()和SetY()或SetXY()。例

$pdf -> SetY(5);    // set the cursor at Y position 5
$pdf -> SetFont('Arial', 'I', 8);  // set the font
$pdf->Cell(40,200,'Descritpion');  // draw a cell at pos 5 that has a a width 40 and height 400