2012-07-31 212 views
0

我正在生成使用yii php中的TCPDF庫的發票的pdf文檔。 地址數據後有一部分與已購物品清單。該列表具有可變長度,這使得很難預測下一部分將呈現的位置。 並在最後有一部分與付款,稅收,運輸等。如何控制tcpdf中的分頁符

我想知道如何使最後一部分是牢不可破的。所以它要麼完全在第一頁上,要麼完全在第二頁上。

是甚至可以嗎?

的情況下,它可以幫助這裏是有問題的部分代碼:

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

回答

9

我知道的方法是首先產生HTML代碼,讓TCPDF將其轉換爲PDF格式,其一般比較容易的代碼,我認爲。然後,您可以使用下面的風格屬性來實現你在找什麼:

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

thx很多它的工作:) – gooy 2012-07-31 12:34:25

+0

請考慮upvoting它並選擇它作爲答案,如果你認爲它有幫助。謝謝。 – inVader 2012-07-31 12:41:10

+0

我選了它,但還不能投票。抱歉。 – gooy 2012-07-31 14:00:22

-2

有這個一個簡單的解決方案,可以包含內容的HTML爲您提供了壓垮<tr>,只需使用nobr="true"
例如:

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