在php中跨页面拥有动态内容 [英] Have dynamic content span across pages in php
问题描述
我有以下代码动态加载发票中的项目。我正在寻找一种将多余项目添加到新页面的方法,依此类推。我想限制一个页面上的项目数量,比如说15个项目。有没有办法在PHP中做到这一点?以下代码位于使用dompdf以页面形式出现的文档中<$ p
$ b
I have the following code that dynamically loads items in an invoice. I am looking for a way to adds excess items to a new page, and so on. I would like to limit the # of items on a page to a set amount, say 15 items. Is there a way to do this in php? The code below is within a document that uses dompdf to appear in pages form
foreach ( $invoice['InvoiceDetail'] as $key=>$item){
$html .= '<tr style="border-bottom: 1px solid #ccc; line-height: 15px;">';
$itemNo = isset($item['product_id']) ? $item['product_id'] : '';
$itemName = isset($item['productName']) ? $item['productName']: '';
$price = isset($item['price']) ? invoiceNumFormat($item['price']): '';
$quantity = isset($item['quantity']) ? $item['quantity'] : '';
$total = invoiceNumFormat( $item['price']*$item['quantity']);
$html .= '<td style="text-align: left"><h5>'.$itemNo.'</h5></td>';
$html .= '<td style="text-align: left">'.$itemName.'</td>';
$html .= '<td style="text-align: left">'.$price.'</td>';
$html .= '<td style="text-align: left" width="10px">'.$quantity.'</td>';
$html .= '<td style="text-align: right">'.$total.'</td>';
$html .= '</tr>';
}
推荐答案
对于您的特定情况,您可以指示dompdf打破该页面,这些内容符合以下内容:
For your particular situation you could just indicate to dompdf to break the page, something along the lines of:
$itemCount = 0;
foreach ( $invoice['InvoiceDetail'] as $key=>$item){
$itemCount++;
$html .= '<tr style="border-bottom: 1px solid #ccc; line-height: 15px;">';
/* snip */
if ($itemCount % 20 == 0) {
$html .= '<tr><td><div style="page-break-before: always;"></div></td></tr>';
}
$html .= '<td style="text-align: left"><h5>'.$itemNo.'</h5></td>';
$html .= '<td style="text-align: left">'.$itemName.'</td>';
$html .= '<td style="text-align: left">'.$price.'</td>';
$html .= '<td style="text-align: left" width="10px">'.$quantity.'</td>';
$html .= '<td style="text-align: right">'.$total.'</td>';
$html .= '</tr>';
}
Dompdf尚未识别表格行/单元格上的分页符样式。否则,将样式放置在那里会更有意义。
Dompdf does not yet recognize page break styling on table rows/cells. Otherwise it would make more sense to place the styling there.
这篇关于在php中跨页面拥有动态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!