如何在tcpdf中控制分页符

时间:2012-07-31 11:01:23

标签: php yii tcpdf

我正在使用yii php中的TCPDF库生成发票的pdf文档。 在地址数据之后,有一部分带有购买物品清单。该列表具有可变长度,这使得难以预测下一部分将呈现的位置。 最后有一部分付款,税款,运费等。

我想知道如何使最后一部分牢不可破。所以它要么完全在第一页,要么完全在第二页。

是否可行?

如果它有帮助,这里是相关部分的代码:

$pdf->SetFont("helvetica", "", 9);
$pdf->Cell(4,0,'Versandart','TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,"$model->versandart",'TBLR',0,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "", 6);
$pdf->Cell(5,0.4,'Hiermit bestätige ich den Auftrag','TLR',1,'R',0,'',0, 0,'','T');
$pdf->SetFont("helvetica", "", 9);
$pdf->Cell(4,0,'Frachtpreis','TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,"$model->versandpreis €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->Cell(5,0,'','LR',1,'R',0,'',0, 0,'','T');
$pdf->Cell(4,0,'Nachnahmegeb.','TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,"$model->nachnahme €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->Cell(5,0,'','LR',1,'R',0,'',0, 0,'','T');
$pdf->Cell(4,0,'SPV-Versicherung','TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,"$model->versicherung €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "B", 6);
$pdf->Cell(5,0.4,'Ort, Datum, Unterschrift','BLR',1,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "", 9);
$pdf->Cell(4,0,'Nettobetrag','TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,$totalSum-($model->vat/100)*$totalSum." €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "", 6);
$pdf->Cell(5,0.4,'Ich erkenne die AGB in der Homepage','TLR',1,'R',0,'',0, 0,'','T');
$pdf->SetFont("helvetica", "", 9);
$pdf->Cell(4,0,"incl. $model->vat% MwSt.",'TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,($model->vat/100)*$totalSum." €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "", 6);
$pdf->Cell(5,0.4,'unter Kontakt nachzulesen hiermit an.','LR',1,'R',0,'',0, 0,'','T');
$pdf->SetFont("helvetica", "", 9);
$pdf->Cell(4,0,'Summe','TLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,$totalSum." €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "B", 6);
$pdf->Cell(5,0.4,'','LR',1,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "", 9);
$pdf->Cell(4,0,'zu bezahlen','TBLR',0,'L',0,'',0, 0,'','T');
$pdf->Cell(8,0,$totalSum-$model->paymentSum." €",'BLR',0,'R',0,'',0, 0,'','B');
$pdf->SetFont("helvetica", "B", 6);
$pdf->Cell(5,0.4,'Ort, Datum, Unterschrift','BLR',1,'R',0,'',0, 0,'','B');
$pdf->Ln();
$pdf->MultiCell(4, 1, 'Hiermit bestätige ich den Auftrag', 'TLR', 'R', 0, 1, '', '', true, 0, false, true, 0, 'T');
$pdf->MultiCell(4, 1, 'Ort, Datum, Unterschrift', 'BLR', 'R', 0, 1, '', '', true, 0, false, true, 0, 'B');

2 个答案:

答案 0 :(得分:10)

我所知道的方法是首先生成HTML代码,然后让tcpdf将其转换为pdf,这通常更容易编码。然后,您可以使用以下样式属性来实现您的目标:

<div style="page-break-inside:avoid;">
some non breakable text
</div>

答案 1 :(得分:-2)

有一个简单的解决方案,您可以包含h​​tml为{4}}提供的内容,只需使用<tr>
例如:

nobr="true"