1
我正在嘗試使用創建一個PDF文件,我需要它自動加載我的文檔,而不是在底部創建空格。mPDF文件自動高度(POS打印機)
這裏是兩個不同內容生成的PDF的兩個圖像。左圖像的內容比右圖像的內容多,因此它在底部創建了更大的空間。
我希望它有沒有空間可言。到目前爲止,這是我嘗試過的。
public function __construct()
{
/*
* Encoding
* Size (Array(Xmm, Ymm))
* Font-size
* Font-type
* margin_left
* margin_right
* margin_top
* margin_bottom
* margin_header
* margin_footer
* Orientation
*/
$this->mPDF = new mPDF('utf-8', array(56, 1000), 9, 'freesans', 2, 2, 2, 0, 0, 0, 'P');
}
它以1000的高度開始文檔,以便比首先要求的長度更長。
public function write($html, $url)
{
/*
* Writing and remove the content, allows the setAutoTopMargin to work
*
* http://www.mpdf1.com/forum/discussion/621/margin-top-problems/p1
*/
$this->mPDF->WriteHTML($html[0]);
$pageSizeHeight = $this->mPDF->y;
$this->mPDF->page = 0;
$this->mPDF->state = 0;
unset($this->mPDF->pages[0]);
foreach($html as $content)
{
$this->mPDF->addPage('P', '', '', '', '', 2, 2, 2, 0, 0, 0, '', '', '', '', '', '', '', '', '', array(56, $pageSizeHeight));
$this->mPDF->WriteHTML($content);
}
$this->mPDF->Output($url);
}
所以,你可以看到,雖然在某些時候調用該函數write()
我搶Y
值,所以我可以用它來設置文件的高度。不幸的是,它沒有達到我期望的效果,這是爲了在沒有任何空白的情況下完全填充文檔。
與$pageSizeHeight
玩也不會有幫助,因爲它可能會在一個文檔工作,但沒有其他,像這樣:
$pageSizeHeight = $this->mPDF->y - 20;