使用fpdf定位单元格[英] positioning the cell in pdf using fpdf

本文是小编为大家收集整理的关于使用fpdf定位单元格的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在尝试从用户以形式输入的数据制作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中的位置,但是我想知道是否有办法无需指定它们. I.E description1和element_1应该在前几行上,描述2应该从element_1结束的位置开始.

推荐答案

"正如您在上面的代码中看到的那样,请提及数据在pdf中的位置"这是不正确的.宽度40和高度为400是您创建的单元格的宽度和高度,而不是PDF上的位置.如果要在PDF上设置单元格的位置,则需要在创建一个单元格之前使用setx()和sety()或setxy()或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

本文地址:https://www.itbaoku.cn/post/2090911.html

问题描述

I am trying to make a pdf from the data entered by the user in a form. I am using fpdf to do this. As of now I have something like this for adding the data to the 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']);

This does work but what I want to know is how can I add these to the pdf without specifying the location. As you can see in the above code I am mentioning where the data should be in the pdf but I want to know if there is a way to do it without specifying them. i.e the description1 and element_1 should be on the first few lines and description2 should start of where element_1 ends.

推荐答案

"As you can see in the above code Im mentioning where the data should be in the pdf" this is incorrect. the width 40 and the height 400 are the width and height of the Cell you are creating not the location on the pdf. If you want to set the location of the cell on the pdf you need to use SetX() and SetY() or SetXY() before you create a cell.Example

$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