duanmei1930 2015-11-27 13:10
浏览 63

TCPDF不会两次打印数组元素

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)