【问题标题】:mpdf table width to fit A4 paper size适合 A4 纸张大小的 mpdf 表格宽度
【发布时间】:2017-02-12 10:49:32
【问题描述】:

我一直在尝试所有可能的解决方案,以使表格填满 A4 纸的宽度。我正在使用 mpdf 将 HTML 转换为 pdf。但表格永远不是 100% 的宽度。 我尝试将宽度设置为 100%、1000px、180mm,但它们都不起作用。请帮忙。

我试过了:

 <table width="1000px">   //style="width:100%;" or width:180mm or width:100px
 </table>

没有任何效果。

【问题讨论】:

    标签: html css mpdf


    【解决方案1】:

    它可能对你有帮助,从 mpdf 配置自定义页面:

    整页示例:

      include 'MPDF/mpdf.php';
      $pdf = new mPDF(); 
      $pdf->ignore_invalid_utf8 = true;
      $header ="Header html file or code";
      $footer ="Footer html file or code";
      $content ="Body html or code";
    
      $pdf->SetDisplayMode('fullpage');
      $pdf->SetHTMLHeader($header);
      $pdf->SetHTMLFooter($footer);
    
      $pdf->WriteHTML($content); // write the HTML into the PDF
      $pdf->Output("pdf/test.pdt", 'F'); // save to file because we can
    

    或者您可以使用自定义边距:

      include 'MPDF/mpdf.php';
      $pdf = new mPDF(); 
      $pdf->ignore_invalid_utf8 = true;
      $header ="Header html file or code";
      $footer ="Footer html file or code";
      $content ="Body html or code";
    
      $pdf->SetHTMLHeader($header);
      $pdf->SetHTMLFooter($footer);
      $pdf->AddPage('', // L - landscape, P - portrait 
        '', '', '', '',
        15, // margin_left
        15, // margin right
        30, // margin top
        30, // margin bottom
        10, // margin header
        10  // margin footer
      ); 
    
      $pdf->WriteHTML($content); // write the HTML into the PDF
      $pdf->Output("pdf/test.pdt", 'F'); // save to file because we can
    

    【讨论】:

    • 问题出在表格宽度上。
    • 如果你的页边距默认设置为15px 那么如何让你的表格100% 宽度呢?我认为您的布局正在获得默认边距,因为您的表格没有以 100% 的宽度工作。
    • 没有。所写的段落覆盖了 100% 的宽度。唯一的问题是表格宽度。
    猜你喜欢
    • 2016-07-28
    • 2013-05-15
    • 2016-10-01
    • 2015-01-16
    • 2019-06-07
    • 2015-07-05
    • 2013-03-16
    • 1970-01-01
    相关资源
    最近更新 更多