如何控制tcpdf中的分页符 [英] how to control page breaks in tcpdf

查看:32
本文介绍了如何控制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');

解决方案

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

一些不可破坏的文本

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

解决方案

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>

这篇关于如何控制tcpdf中的分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆