mPDF setAutoMargin not working for first page

强颜欢笑 提交于 2020-01-25 04:26:26

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!