8

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.

Entwickler
  • 255
  • 2
  • 12
user2636368
  • 622
  • 4
  • 10
  • 20

1 Answers1

16

"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
bassxzero
  • 4,838
  • 22
  • 34
  • okay. but now my question is can I do it without specifying the width and the height of the cell – user2636368 Nov 06 '13 at 16:54
  • $pdf->Cell(0,0,'Descritpion'); If you put zeros in the width create the cell and extend the width until the right margin. I'm not sure what it does for the height if you put in 0. http://www.fpdf.org/ this site will help. Click manuals then Cell – bassxzero Nov 06 '13 at 16:58
  • $pdf->Cell(0,0,'Descritpion'); doesn't work. It places it almost outside the page and at top of the page. – user2636368 Nov 06 '13 at 17:02
  • Did you set the x and y first? Try $pdf -> SetXY(100,100); // set the cursor at Y position 5 $pdf -> SetFont('Arial', 'I', 8); // set the font $pdf->Cell(0,0,'Descritpion'); It should creat a cell at 100,100 that extends all the way to the right margin of the pdf. – bassxzero Nov 06 '13 at 17:07
  • I figured out how to position it thanks. But know when I do it the whole data from the text input is displayed in one line how can I break it down into multiple lines? – user2636368 Nov 06 '13 at 17:36
  • @user2636368 need to use MultiCell() not Cell(). – bassxzero Nov 06 '13 at 20:06