views:

1738

answers:

4

Hi this might seem like a weird question. Anyway, I'm generating some PDF file on the fly using PHP and some third party code I found. My problem is I need to insert line breaks in some part of the text that will be inserted in the PDF file. Something like:

$pdf->InsertText('Line one\n\nLine two');

So it prints

Line one

Line two

I know \n doesn't work on PDF, but do you guys know any character or something that represents a line break on these files?

Thank you.

+2  A: 

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.

thomasrutter
A: 
$pdf->InsertText('Line one

    Line two');

I'm not sure about pdf files, but it works when echo'ing to a normal html page.

McAden
A: 

Your code reads

$pdf->InsertText('Line one\n\nLine two');

I don't know about the PDF library you're using but normally if you want \n to be interpreted as a line break you must use double quotes in PHP, e.g.

$pdf->InsertText("Line one\n\nLine two");
David Caunt
A: 

You state that "2 is the height of the multi-line text box" No it's not.

2 is the distance between lines of text.

I don't think there is a real way of calculating the height of the actual resulting text box unless you use GetY(); and then subtract you origional Y value you used in your SetXY() statement for placing the Multicell in the first place.

Nicolas