【问题标题】:mPDF - footer is working only on last pagemPDF - 页脚仅在最后一页有效
【发布时间】:2016-07-24 19:16:38
【问题描述】:

我在这里看到了其他类似的问题,但我无法解决我的问题。 我的问题是:页眉在所有页面中都正常工作,但页脚只显示在最后一页。

<?
$mpdf = new mPDF(   '',    // mode - default ''
                '',    // format - A4, for example, default ''
                0,     // font size - default 0
                '',    // default font family
                15,    // margin_left
                15,    // margin right
                58,     // margin top
                60,    // margin bottom
                6,     // margin header
                0,     // margin footer
                'L' );  // L - landscape, P - portrait
$mpdf->SetDisplayMode('fullpage');

$cabecalho = '<div>header</div>'; 
$paragrafo = '<div>body</div>'; 
$stylesheet = "table{
                  width: 100%;
                  text-align:center;
                  border: 2px solid black;
               }
";

$footer = "<table name='footer' width=\"1000\">
           <tr>
             <td style='font-size: 18px; padding-bottom: 20px;' align=\"right\">{PAGENO}</td>
           </tr>
         </table>";
$mpdf->SetHTMLHeader($cabecalho);

$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($paragrafo);

$mpdf->SetFooter($footer);

$mpdf->Output();
exit;
?>

这里的页脚有什么问题?

【问题讨论】:

  • 试试这个SetHTMLFooter() 而不是SetFooter()
  • @severinolorillajr 我也试过了,同样的问题
  • 我编辑了问题,并把我的代码开始
  • 你最近检查过文档吗?

标签: php footer mpdf


【解决方案1】:

尝试将setFooter() 放在WriteHTML() 之前

$mpdf->SetHTMLHeader($cabecalho);
$mpdf->SetFooter($footer);
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML($paragrafo);
$mpdf->AddPage('','','','b','off');
$mpdf->Output();

【讨论】:

  • 这打破了setAutoBottomMargin =&gt; 'stretch' & 定义margin_bottom :/
  • 啊,没关系!经过几个小时的努力,我终于开始工作了! SetHTMLFooter 需要在样式表和 html 之间设置!然后它出现在每个页面上,并且自定义底部边距有效。
【解决方案2】:

使用SetHTMLFooter() 并将其添加到WriteHTML() 之前SetHTMLHeader() 之后

希望能解决页脚问题

其他信息:

void SetHTMLFooter(String $html, string $side)

void SetFooter($footer, $side)

SetFooter 已被弃用,但仍可使用..

$footer = array(
    'L' => array {
        'content' => '',
        'font-size' => 10,
        'font-style' => 'B',
        'font-family' => '',
        'color' => '#000000'
    },
    'C' => array {
        'content' => '',
        'font-size' => 10,
        'font-style' => 'B',
        'font-family' => '',
        'color' => '#000000'
    },
    'R' => array {
        'content' => '',
        'font-size' => 10,
        'font-style' => 'B',
        'font-family' => '',
        'color' => '#000000'
    },
    'line' => 1
);

$side 可以是 O 奇数页,E 偶数页或空白页。

有关文档,请查看此链接

http://www.mpdfonline.com/repos/mpdfmanual.pdf

【讨论】:

  • 这个页脚数组在做什么?我不明白
  • 你可以试试这个:使用SetHTMLFooter()并在WriteHTML()之前添加它希望能解决页脚问题..@AlexandreMartinsMontebelo
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多