gpt4 book ai didi

php - 防止 mPDF 中的正文重叠页脚

转载 作者:IT王子 更新时间:2023-10-29 00:06:15 26 4
gpt4 key购买 nike

我正在使用 mPDF 库生成 PDF,我的页眉和页脚的大小取决于几个参数。

静态解决方案是设置页脚边距,这将解决重叠问题 - 但由于页脚大小可能不同,这不是我满意的解决方案。有没有办法获取页脚尺寸并相应地应用边距?

最佳答案

问题出在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);

关于php - 防止 mPDF 中的正文重叠页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10931948/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com