dt614037527 2017-01-19 14:36
浏览 29
已采纳

php表中断页面,下一页没有行

I am having a php table which contains information about billing of certain numbers. After generating this table I export it in pdf using mpdf. If the table has a certain number of rows it breaks the page in a weird way, leading the headers repeat on the next page with no rows. Here is the format of the table:

The table contains up to 3 headers inside <thead> tags, like this:

<table class="items" width="100%" style="font-size: 9pt; border-collapse: collapse;" cellpadding="8">
    <thead>
        <tr>
            <td width="30.3%">Forbrug</td>
            <td width="23.1%">Periode</td>
            <td width="10.76%">Tid/MB</td>
            <td width="9.28%">Enheder</td>
            <td width="12.9%" align="right">I alt</td>
            <td width="13.3%" align="right">I alt+<b>moms</b></td>
        </tr>
    </thead>

rows are added in a while from the database in this way.. nothing special

<tr>
    <td>'.$produktNameFromDatabase.'</td>
    <td>'.$periodeFromDatabase.'</td>
    <td>'.$tidMbFromDatabase.'</td>
    <td>'.$enhederFromDatabase.'</td>
    <td align="right">'.number_format((float)$produktpris, 2, ',', '.').' kr.</td>
    <td align="right"><b>'.number_format((float)$produktpris*(1 + (0.25 * $moms)) - $momsDiscount, 2, ',', '.').' kr.</b></td>
</tr>

with the total lines at the end

        <tr>
            <td class="blanktotal" colspan="1" rowspan="6"></td>
            <td class="blanktotal" colspan="1" rowspan="6"></td>
            <td class="totals" colspan="2">Subtotal:</td>
            <td class="totals" colspan="2">'.number_format((float)$pris1, 2, ',', '.').' kr.</td>
        </tr>
        <tr>
            <td class="totals1" colspan="2">Moms:</td>
            <td class="totals1" colspan="2">'.number_format((float)$pris1*(0.25 * $moms) - $momsTotal, 2, ',', '.').' kr.</td>
        </tr>
        <tr>
            <td class="totals1" colspan="2"><b>TOTAL:</b></td>
            <td class="totals1" colspan="2"><b>'.number_format((float)$pris1*(1 + (0.25 * $moms)) - $momsTotal, 2, ',', '.').' kr.</b></td>
        </tr>
    </tbody>
</table>

!!! EVERYTHING that you have seen by now, including the totals are a part of the table!

Here is the mpdf settings that I have:

In PhP:

$mpdf=new mPDF('win-1252','A4','','',20,15,48,25,10,10);
$mpdf->useOnlyCoreFonts = true;    // false is default
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("Suggestive Title");
$mpdf->SetAuthor("Author");
$mpdf->SetWatermarkText("Faktura");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->SetDisplayMode('fullpage');

In HTML:

$html .= '<!--mpdf
    <htmlpageheader name="myheader">
        <table width="100%"><tr>
            <td width="50%" style="color:#000000;">
                <span style="font-weight: bold; font-size: 14pt;">
                    Company Name
                </span>
                Company Information
            </td>
            <td width="50%" style="text-align: right;">
                <img src="image.jpg" />
                    Invoice Information <br />Side: {PAGENO} af {nb}
                </td>
        </tr></table>
    </htmlpageheader>

    <htmlpagefooter name="myfooter">
        <div style="border-top: 1px solid #000000; font-size: 9pt; text-align: center; padding-top: 3mm; ">
            Footer Stuff
        </div>
        <div style="font-size: 9pt; text-align: center;">
            Other Footer Stuff
        </div>
    </htmlpagefooter>

    <sethtmlpageheader name="myheader" value="on" show-this-page="1" />
    <sethtmlpagefooter name="myfooter" value="on" />
mpdf-->';

Some styling that I use

body {font-family: sans-serif;
    font-size: 10pt;
}
p { margin: 0pt;
}
td { vertical-align: top; }
.items td {
    border-left: 0.1mm solid #000000;
    border-right: 0.1mm solid #000000;
}
table thead td { background-color: #d4ffaa;
    border: 0.1mm solid #000000;
}
.items td.blanktotal {
    background-color: #FFFFFF;
    border: 0mm none #000000;
    border-top: 0.1mm solid #000000;
    border-right: 0.0mm solid #000000;
}
.items td.totals {
    text-align: right;
    border-top: 0.1mm solid #000000;
    border-right: 0.0mm solid #000000;
    border-left: 0.0mm solid #000000;
}
.items td.totals1 {
    text-align: right;
    border-top: 0.0mm solid #000000;
    border-right: 0.0mm solid #000000;
    border-left: 0.0mm solid #000000;
}

The result looks something like this:

enter image description here

This issue occurs only when the number of rows fills the page. If it overflows it is no major issue, because the table headers are still there on the next page (all of them unfortunately, not only the last one) and the rest of the rows are added further.

How can I get rid of those empty rows, in this special case?

Thank you!

!!EDIT: Added more information, code and a better image of the case. Sorry for not doing it at the first time!

!!EDIT #2: I just observed on other examples that had more than 1 page of rows that the <thead>s keep their position on next pages. It happens all the time. Is there a way to disable that so that other <thead>s will just continue on the next page from the top of the page without remembering the position from the previous page?

  • 写回答

2条回答 默认 最新

  • douzhuangna6906 2017-02-01 12:36
    关注

    I eventually found a solution. Best way to get rid of these things is to replace <thead> tags with <th>. <thead> has a predefined style which makes the table header repeat itself on every page. <th> will make the header stop repeating itself on the next pages (fortunate or unfortunate), but it will eliminate the space caused by the <thead>'s style

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料