PHP MPDF。 <htmlpageheader>弄乱了我的容器数据

时间:2015-08-02 17:22:46

标签: pdf pdf-generation mpdf

您好我的MPDF html中存在转换为pdf的问题。以下是我的代码和截图:

HTML

<htmlpageheader name="header1">
        my html code here
</htmlpageheader>


<div> my data here... </div>

CSS

@page {
        header: html_header1; 
    }

下面的截图:

enter image description here

1 个答案:

答案 0 :(得分:1)

如果您的标题是每页发布的,则根据手册忽略标题高度:http://mpdf1.com/manual/index.php?tid=411

我通过在HTML主体的顶部添加一个spacer div来解决这个问题:

<div style="height: 140px"></div>

不完美但有效。

如果您有适用于所有页面的标题,请查看MPDF config.php文件的此部分:

// If 'pad' margin-top sets fixed distance in mm (padding) between bottom of header and top of text.
// If 'stretch' margin-top sets a minimum distance in mm between top of page and top of text, which expands if header is too large to fit.
$this->setAutoTopMargin = false;
$this->setAutoBottomMargin = false; 
$this->autoMarginPadding = 2;       // distance in mm used as padding if 'stretch' mode is used

如果setAutoTopMargin设置为false(默认值),那么您的标题也会被忽略。尝试将其设置为&#39; pad&#39;在这种情况下。