html - 下一页有不同边距的 TCPDF 表头

标签 html css tcpdf

我需要打印一个带有重复表格的 pdf,具体取决于它在第一页中工作正常的记录数量,但在下一页表格标题更改边距,这是在 TCPDF 上显示我的表格的代码;

$html= '<table cellpadding="5">
        <tr>
            <td colspan="2" align="center"><u><h1>Resumen de Ingresos</b>
        </tr>
        <tr>
            <td>De Fecha: {desd_fecha}</td> <td>A Fecha: {hasta_fecha}</td>
        </tr>            
     </table>';
$total=0;
$html .='   <table  border="1" cellpadding="5" width="100%">      
        <thead>
        <tr>
                <th style= "width: 150px";>Fecha</th>
                <th style= "width: 90px";>Nro. Doc.</th>
                <th style= "width: 280px";>Proveedor</th>
                <th style= "width: 180px";>Almacen</th>
                <th style= "width: 90px"; >Costo</th>
        </tr>
        </thead>
        <tbody>';     
foreach ($datos_pdf as $datos_pdfs){
$total += $datos_pdfs["DetAsiento"]["haber"];  
$html .='
    <tr>
        <td align="center" style= "width: 150px";>'.date("d-m-Y", strtotime($datos_pdfs['CabAsiento']['fecha'])).'</td>
        <td align="left" style= "width: 90px";>'.$datos_pdfs["CabAsiento"]["nro_doc"].'</td>
        <td align="left" style= "width: 280px";>'.$datos_pdfs["Category"]["name"].'</td>
        <td align="left" style= "width: 180px";>'.$datos_pdfs["Category"]["nro_cuenta"].'</td>
        <td align="left" style= "width: 90px"; >'.$datos_pdfs["DetAsiento"]["haber"].'</td>
    </tr>
</tbody>'; 
}
$html .='
    <tr>
        <td colspan="5" align="right"><b>Total: '.$total.'</b></td>
    </tr>
    </table>';
$fecha = new DateTime($desde);
$html = str_replace('{desd_fecha}',$fecha->format('d/m/Y'),$html);
$fecha = new DateTime($hasta);
$html = str_replace('{hasta_fecha}',$fecha->format('d/m/Y'),$html);
$pdf->writeHTML($html, true, false, false, false, '');
$pdf->lastPage();

我下一页的输出是这样的:

enter image description here

我怎样才能使表格的标题与第一个表格的页边距相同。

最佳答案

你可以这样使用它:

$html = <<<EOD
<table border="1" cellspacing="5" width="100%">
  <thead>
    <tr>
      <th style= "width: 150px";>Fecha</th>
      <th style= "width: 90px";>Nro. Doc.</th>
      <th style= "width: 280px";>Proveedor</th>
      <th style= "width: 180px";>Almacen</th>
      <th style= "width: 90px"; >Costo</th>
    </tr>
  </thead>
  <tbody>
EOD;

关于html - 下一页有不同边距的 TCPDF 表头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35141087/

相关文章:

html - 如何使用 CSS 创建模板?

html - 是否有任何常见的电子邮件客户端预取链接而不是图像?

javascript - 用于在滚动时将元素 "fly"打开/关闭屏幕的插件

html - 具有动态大小的纯 CSS 下拉菜单?

pdf - 如何在 TCPDF 中实现自定义字体

php - crontab 和 PHP

html - 如何使使用TCPDF生成的pdf表格居中?

html - 给父 div float 内容的宽度

html - 如何在 HTML/CSS 中设置百分比高度值

html - 自定义 CSS webkit 滚动条在 Firefox 浏览器中不起作用