Kuya A
Kuya A

Reputation: 351

PHP MPDF. <htmlpageheader> messes up my container data

Hi I have a problem in my MPDF html to convert in pdf. Here is my code and screenshot below:

HTML

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


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

CSS

@page {
        header: html_header1; 
    }

Screenshot below:

enter image description here

Upvotes: 1

Views: 2599

Answers (1)

Dan Hobbs
Dan Hobbs

Reputation: 63

If your header is posted per page, then the header height is ignored according to the manual: http://mpdf1.com/manual/index.php?tid=411

I have worked around this by adding a spacer div to the top of the main body of my HTML:

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

Not perfect but it works.

If you have headers which apply to all pages, then look at this section of the MPDF config.php file:

// 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

If setAutoTopMargin is set to false (the default) then your header is also ignored. Try setting it to 'pad' in this case.

Upvotes: 2

Related Questions