i'm working on a project to create a pdf invoice from user input.
The input is put into an array: array('input1' => 'value1', 'input2' => 'value2')
I let my PHP parse the array and calculate necessary height / width for TCPDF to be able to print everything with borders in the right place.
Now if the user input1 and input2 are different everything works fine, but if they are exactly the same (which is a possibility) TCPDF only prints the second input.
Here is my code:
public function PrintInvoiceContent() {
// settings
$rowcount = 0;
$borderL = 'L';
$borderR = 'R';
$firstBorder = true;
$firstInfo = true;
$lastBorder = true;
$dimensions = $this->getPageDimensions();
foreach ($this->input['invoice_content'] as $key => $value) {
// key contains text, value contains actual amount in dollar
// measurements
$lines = ($this->getNumLines($key, 130) * 5);
$rowcount = $rowcount + $lines;
$startY = $this->GetY();
$height = ceil($startY + $rowcount + $dimensions['bm']);
if (floor($dimensions['hk']) - $height < 1) {
$borderL = 'LB';
$borderR = 'RB';
$firstBorder = true;
$lastBorder = false;
} else if (floor($dimensions['hk']) - $height == 1) {
$borderL = 'LB';
$borderR = 'RB';
$firstBorder = true;
$lastBorder = true;
}
if ($firstBorder) {
$this->Cell(0, 5, '', 'LTR', 1);
if ($firstInfo) {
$this->Cell(14, ($this->getNumLines($this->input['betreft'], 153) * 5), 'About: ', 'L', 0, 'L', false);
$this->MultiCell(156, ($this->getNumLines($this->input['betreft'], 153) * 5), $this->input['About'], 'R', 'L', false);
// prints discription of bill contents
$this->Cell(0, 5, '', 'LR', 1, 'L', false);
$firstInfo = false;
}
$this->MultiCell(130, $lines, $key, $borderL, 'L', false, 0);
$this->Cell(40, $lines, $value, $borderR, 1, 'L', false);
$firstBorder = false;
} else {
$this->MultiCell(130, $lines, $key, $borderL, 'L', false, 0);
$this->Cell(40, $lines, $value, $borderR, 1, 'L', false);
}
$this->Cell(0, 2, '', 'LR', 1);
}
}
If the user input varies as much as 1 character everything works fine. Does anyone know why the first input is omitted if the pieces of input are exactly the same?