0

I must add a linebreak for my images to appear after each other. I have tried the following but it does not work.

$rs['imagepath'] = $imagepath;
    $pdf->Image("{$imagepath}\n");

The original code to output the images is below, but it outputs only the first index and the second and third images does not come up... :(

$rs['imagepath'] = $imagepath;
    $pdf->Image("{$imagepath}");

The result is in a foreach loop like this:

     foreach($select as $index => $rs) 
{    
        $rs['imagepath'] = $imagepath;
        $pdf->Image("{$imagepath}"); 
}
J. Doe
  • 63
  • 1
  • 1
  • 12

2 Answers2

1

You can use ln() function i think.you have to define every image in one line

$fpdf->ln();
  • I can not define evey image seperately, The images must loop by themselves if there are more than one images. And thats why I want a linebreak. Can you give an example? – J. Doe Jun 24 '17 at 11:36
  • 1
    have a look on this link 1.https://stackoverflow.com/questions/861809/inserting-line-breaks-into-pdf 2.http://www.fpdf.org/en/tutorial/tuto1.htm – Jawahar Sharma Jun 24 '17 at 11:40
  • Here is my only input: '$rs['imagepath'];. And I want to add a linebreak after this input. And the loop will do the rest. – J. Doe Jun 24 '17 at 12:05
1

I think your code has a mistake, try the below code to iterate over the $rs array. in the current code, your $imagepath variable is always remain same. you can then print a \n characters to pdf for printing new lines

foreach($select as $index => $rs) 
{    
        $imagepath = $rs['imagepath'];
        $pdf->Image("{$imagepath}"); 
}

Edit: I found this on another stack overflow thread

If you are using fpdf, in order to be able to use line breaks you will need to use a multi-line text cell as described here.

If you use this, then line breaks in your text should be interpreted and converted correctly.

Just a quick example:

$pdf->Multicell(0,2,"This is a multi-line text string\nNew line\nNew line"); 

Here, 2 is the height of the multi-line text box. I don't know what units that's measured in or if you can just set it to 0 and ignore it. Perhaps try it with a large number if at first, it doesn't work.

Shobi
  • 10,374
  • 6
  • 46
  • 82
  • Can you give an example of how to use the '/n' for linebreak for a loop? – J. Doe Jun 24 '17 at 11:39
  • I dont know what to add into new lines. It is an automatic loop and I only got one input which will loop all of the results. Here is my only input: '$rs['imagepath'];'. And I also don't know how to output an image into a multicell. In this case only file name is going to be outputted. I want the image itself to me outputted. – J. Doe Jun 24 '17 at 12:04
  • 1
    Then what I suggest you is to refer some more places and learn some more. and I don't understand what you mean by an automatic loop :(). the multicell i suggested was to output a new line, to print an image to pdf you can check this http://www.fpdf.org/en/doc/image.htm – Shobi Jun 24 '17 at 12:11