简体   繁体   中英

How do I define SetXY and Cell with FPDF PHP Class?

I recently went to this tutorial who explains how to create a PDF file with FPDF PHP Class. Everything works great but I have some questions that this blog does not answer properly.

http://wpeasytuts.com/design-create-pdf-with-php/

On the last part, the author is saying :

    //Add Name for Invoice
$pdf->SetXY(31,37);
$pdf->SetFillColor(255,255,255);
$pdf->SetFont('Arial','',9);
$pdf->Cell(50, 4, "John Doe", 0, 1,'L',1);

How do he knows this paramaters ? How do I know those parameters are correct if I want to create my own pdf file ? How does he knows when the pdf is generated it is (31,37) ? same for the $pdf ->cell (50, 4, "John DOE" ... )

How do we find the right number ? I checked online, on google, everywhere. Is there is a tool or some website explaining how to find those right number ?

$pdf->SetXY(31,37);

How does it know it is 31 How does it know it is 37 ?

Where can I find this trick to place it correctly ?

Someone knows ?

You are right to query that minimal code example as we will see there is a misleading error that perplexed me until I tried to emulate what you were given.

You want to know where the location numbers come from, and in a way that's eventually decided by yourself when you build your own "Template".

Here I am using the example given and we can see from the values at lower border (sorry they are cm so multiply by 10 for mm) that the 9 point high text would need to be positioned to the right of Name: at an arbitrary 31 mm from left edge and also 37 from top edge.

As to why 50,4 well there is a mistake as we see it should be minimal 50,14 and for "Quasimo Doe" it would need to be much longer than 50, so it would be much better if the last line was

$pdf->Cell(150, 14, "John Doe", 0, 1,'L',1);

在此处输入图片说明

For more info on the syntax of that command (and others) see http://fpdf.org/en/doc/cell.htm

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