how to control page breaks in tcpdf

烂漫一生 提交于 2019-12-10 11:57:45

问题


i'm generating a pdf document for an invoice using TCPDF library in yii php. after the address data there a part with the list of bought items. that list is of variable lenght which makes it hard to predict where the next part will render. and at the end there is a part with payment, taxes, shipping etc.

i would like to know how to make that last part be unbreakable. so it's either entirely on the first page or entirely on the second page.

is that even doable?

in case it helps here's the code for the part in question:

$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');

回答1:


The way I know of would be to generate HTML code first and let tcpdf convert it to pdf which is generally easier to code I think. You can then use the following style attribute to achieve what you're looking for:

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



回答2:


There is a simple solution for this, you can include what html provides you for the <tr> that breaks, simply use nobr="true"
For example:

<table><tr nobr="tr">
<td>
<td/>
</tr>
</table>


来源:https://stackoverflow.com/questions/11738638/how-to-control-page-breaks-in-tcpdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!