Krk*_*kec 2 php pdf-generation tcpdf
我正在尝试在 TCPDF 中创建发票,但无法创建表。表格单元格必须自动换行。我阅读了大量网站如何做到这一点,但我无法做到正确。
\n\n问题出在第二行,我可以让单元格对齐。\n单元格高度有问题 http://apartman-donat.com/Capture.JPG
\n\n这是我的代码:
\n\n$pdf->ln(20);\n$w = array(10, 80, 15, 25,30,35);\n$pdf->SetFillColor(127, 127, 127);\n$pdf->SetTextColor(255,255,255);\n$pdf->SetDrawColor(127, 127, 127);\n$pdf->SetLineWidth(0.3);\n$pdf->SetFont($fontname,\'\',12);\n$pdf->Cell($w[0], 10, \'#\', 1, 0, \'C\', 1);\n$pdf->Cell($w[1], 10, \'OPIS USLUGE\', 1, 0, \'C\', 1);\n$pdf->Cell($w[2], 10, \'J.mj.\', 1, 0, \'C\', 1);\n$pdf->Cell($w[3], 10, \'Koli\xc4\x8dina\', 1, 0, \'C\', 1);\n$pdf->Cell($w[4], 10, \'Cijena\', 1, 0, \'C\', 1);\n$pdf->Cell($w[5], 10, \'Iznos [Kn]\', 1, 0, \'C\', 1);\n$pdf->ln();\n$pdf->SetFillColor(255, 255, 255);\n$pdf->SetTextColor(0,0,0);\n$pdf->SetDrawColor(127, 127, 127);\n$pdf->SetLineWidth(0.3);\n$pdf->SetFont($fontname,\'\',8);\n//$pdf->setFontSpacing(0);\n//$pdf->setCellHeightRatio(0.8);\n//$pdf->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $stretch, $ishtml, $autopadding, $valign, $fitcell);\n$pdf->MultiCell($w[0], 15, \'1\', 1, \'C\', false, 0, \'\', \'\', false, 0, false, false, 15,\'T\', false);\n$pdf->MultiCell($w[1], 15, \'Energetski pregled i izrada energetskog certifikata stana na adresi: Petrova ul. 33, 10000 Zagreb\', 1, \'L\', false, 0, \'\', \'\', false, 0, false, false, 0,\'T\', false);\n$pdf->MultiCell($w[2], 15, \'kom\', 1, \'C\', false, 0, \'\', \'\', false, 0, false, false, 15,\'B\', false);\n$pdf->MultiCell($w[3], 15, \'1\', 1, \'C\', false, 0, \'\', \'\', false, 0, false, false, 15,\'B\', false);\n$pdf->MultiCell($w[4], 15, \'600.00\', 1, \'C\', false, 0, \'\', \'\', false, 0, false, false, 15,\'B\', false);\n$pdf->MultiCell($w[5], 15, \'600.00\', 1, \'C\', false, 0, \'\', \'\', false, 0, false, false, 15,\'B\', false);\nRun Code Online (Sandbox Code Playgroud)\n\n我究竟做错了什么?
\nMultiCell首先,您需要根据大小设置设置/估计函数中每行最多可以显示多少个字符width。比如刚才说的大约48个字符。
$textlength = strlen('Energetski pregled i izrada energetskog certifikata stana na adresi: Petrova ul. 33, 10000 Zagreb');
$rowheight = 15;
if ($textlength > 48){ // alocate as you need
if ($textlength > 144){
$rowheight = $rowheight *4;
} else if ($textlength > 96){
$rowheight = $rowheight *3;
} else {
$rowheight = $rowheight *2;
}
}
$pdf->MultiCell($w[0], $rowheight, '1', 1, 'C', false, 0, '', '', false, 0, false, false, 15,'T', false);
$pdf->MultiCell($w[1], 15, 'Energetski pregled i izrada energetskog certifikata stana na adresi: Petrova ul. 33, 10000 Zagreb', 1, 'L', false, 0, '', '', false, 0, false, false, 0,'T', false);
$pdf->MultiCell($w[2], $rowheight, 'kom', 1, 'C', false, 0, '', '', false, 0, false, false, 15,'B', false);
$pdf->MultiCell($w[3], $rowheight, '1', 1, 'C', false, 0, '', '', false, 0, false, false, 15,'B', false);
$pdf->MultiCell($w[4], $rowheight, '600.00', 1, 'C', false, 0, '', '', false, 0, false, false, 15,'B', false);
$pdf->MultiCell($w[5], $rowheight, '600.00', 1, 'C', false, 0, '', '', false, 0, false, false, 15,'B', false);
Run Code Online (Sandbox Code Playgroud)