line break problem with MultiCell in FPDF

user156073 picture user156073 · Sep 14, 2009 · Viewed 50.9k times · Source

I am using java port of fpdf. I am encountering fowwlowing errors.

1).When i call multicell 2 times every time the text is printed on a new line.

MultiCell(0, 1, "abcd", currentBorders, Alignment.LEFT, false); //prints on one line
 MultiCell(0, 1, "efg", currentBorders, Alignment.LEFT, false); //prints on next line

I want that there is no line break after the call to multicell. How can i do it?

2)If i do the following thing then some part of my string gets printed on one line and some on next.

 MultiCell(getStringWidth(myString), 1, myStringcurrentBorders, Alignment.LEFT, false);

3)If i do the following thing then there are many blank lines after the line on which myString is printed. It works correctly if i use one 1 ans second parameter

 MultiCell(0, myFontSize, "123456", currentBorders, Alignment.LEFT, false);

What is the problem?

Answer

Joshua Pinter picture Joshua Pinter · Apr 22, 2010

I would get the current Y position before writing the MultiCell and then move the "cursor" back to that Y position after the MultiCell generation. Like this:

$current_y = $pdf->GetY();
$current_x = $pdf->GetX();

$cell_width = 50;
MultiCell($cell_width, 1, "abcd", currentBorders, Alignment.LEFT, false);

$pdf->SetXY($current_x + $cell_width, $current_y);

$current_x = $pdf->GetX();
MultiCell($cell_width, 1, "abcd", currentBorders, Alignment.LEFT, false);

Something like that.