2012-06-07 25 views
10

我使用mPDF庫生成PDF文件,並且根據幾個參數的不同,我的頁眉和頁腳大小也不同。防止mPDF中的文本重疊頁腳

一個靜態解決方案是設置頁腳邊距,這將解決重疊問題 - 但由於頁腳尺寸可能有所不同,這不是我感到滿意的解決方案。有沒有辦法獲得頁腳尺寸並相應地應用邊距?

+0

我有同樣的問題ATM,如果你找到了解決方案,你可以請更新你的問題? – Bogdan

+0

我已在下面更新了我的答案。希望它會幫助你。必須爲margin_header/footer設置文檔邊距。您可能還需要在配置文件中禁用'setAutoTopMargin'設置。 – Daniel

回答

18

問題在於mpdf的文檔。我認爲margin_footer和margin_header是文檔正文和這些之間的差距。相反,margin_footer和margin_header是文檔邊距,正如人們所認爲的margin_top和margin_bottom那樣。

因此,更改底部和頂部邊距將決定文檔正文的起始位置。並且更改頁眉/頁腳邊距將決定打印頁邊距。

希望它有幫助!

更新答案

MPDF文檔是有點過了構造函數調用,我猜。 margin_top/bottom參數實際上是內容邊距,不適用於margin_header/footer參數。 (如果我沒記錯的話)。 margin_top/bottom是文檔頂部的絕對邊距,並應包含頁眉/頁腳的高度。

這裏是處理邊緣的正確方法:

/** 
* Create a new PDF document 
* 
* @param string $mode 
* @param string $format 
* @param int $font_size 
* @param string $font 
* @param int $margin_left 
* @param int $margin_right 
* @param int $margin_top (Margin between content and header, not to be mixed with margin_header - which is document margin) 
* @param int $margin_bottom (Margin between content and footer, not to be mixed with margin_footer - which is document margin) 
* @param int $margin_header 
* @param int $margin_footer 
* @param string $orientation (P, L) 
*/ 
new mPDF($mode, $format, $font_size, $font, $margin_left, $margin_right, $margin_top, $margin_bottom, $margin_header, $margin_footer, $orientation); 
+10

感謝您的更新,也是「實驗設置」'$ mpdf-> setAutoTopMargin ='stretch'和$ mpdf-> setAutoBottomMargin ='stretch''設置將確保頁眉和頁腳不會與主體重疊,手動計算頁眉和頁腳邊距。在處理動態的,用戶創建的頁眉和頁腳時非常有用 – Bogdan

+0

Woah!不知道這是可能的。感謝您的信息,它很快就會派上用場。 – Daniel

+0

我試過$ mpdf-> setAutoBottomMargin ='stretch'沒有成功,請指教如何使用它? – Aiphee

6
$mpdf->setAutoBottomMargin = 'stretch'; 

爲我工作。我所要做的只是確保我在頁腳前加入了這個選項。

+0

直到我將其設置在頁腳之前,它才適用於我。 –