问题
The following code works perfectly for the second, third etc pages, but not for the first one.
/*
* Encoding
* Size (A4, etc)
* Font-size
* Font-type
* margin_left
* margin_right
* margin_top
* margin_bottom
* margin_header
* margin_footer
* Orientation
*/
$this->mPDF = new mPDF('utf-8', 'A4', 9, 'freesans', 10, 10, 0, 25, 5, 4, 'P');
$this->mPDF->setAutoTopMargin = 'pad';
$html = '<sethtmlpageheader name="myheader" value="on" show-this-page="1"></sethtmlpageheader>';
In the first page, the body content overlap the header content, while on the other pages the body content doesn't overlap the header content and fits perfectly below the header.
I want the same behavior on the first page, how do I do it?
EDIT 1: An image to illustrate the problem I'm facing
回答1:
I found out this answer http://www.mpdf1.com/forum/discussion/621/margin-top-problems/p1 which basically reports my issue. The solution is to add a page and delete it so the code calculates the margins and then add again the page.
$this->mPDF->WriteHTML($html);
$this->mPDF->page = 0;
$this->mPDF->state = 0;
unset($this->mPDF->pages[0]);
来源:https://stackoverflow.com/questions/32142922/mpdf-setautomargin-not-working-for-first-page