mpdf表格宽度适合A4纸张尺寸

时间:2016-10-04 10:01:45

标签: html css mpdf

我一直在尝试各种可能的解决方案,使表格填充A4纸的宽度。我使用mpdf将HTML转换为pdf。但表永远不是100%宽度。 我尝试给出100%,1000px,180mm的宽度,但没有一个工作。请帮助。

我试过了:

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

没有任何效果。

1 个答案:

答案 0 :(得分:0)

  

它可能会对您有所帮助,从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
相关问题