php TCPDF - 如何调整标题的高度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5503969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TCPDF - How to adjust height of header?
提问by ryaa
I am using TCPDF to convert html to pdf format. I am passing a string into the php script to be set as my header. I am having a hard time setting the height of my header. I have tried using SetMargins(PDF_MARGIN_LEFT, 0, PDF_MARGIN_RIGHT)
and SetHeaderMargin(0)
. What it did was to only take off the top margin. I have also alternately looked into adjusting the height of the cell which contains the string within the header.
我正在使用 TCPDF 将 html 转换为 pdf 格式。我正在将一个字符串传递到 php 脚本中以设置为我的标题。我很难设置标题的高度。我试过使用SetMargins(PDF_MARGIN_LEFT, 0, PDF_MARGIN_RIGHT)
和SetHeaderMargin(0)
。它所做的只是去掉了上边距。我还交替研究了调整包含标题中字符串的单元格的高度。
$this->Cell(0, 0, $newHeaderString, 0, false, 'C', 0, '', 0, false, 'M', 'M');
No luck eliminating white space here either.
也没有运气在这里消除空白。
I have included an image to show what white space I want to eliminate. The white space is between the header text and the hr tag from the html. Any help would be appreciated!
我已经包含了一个图像来显示我想要消除的空白区域。空白位于标题文本和 html 中的 hr 标记之间。任何帮助,将不胜感激!
回答by Seyeong Jeong
You could define the PDF_MARGIN_TOP
constant or you could set the margin explicitly:
您可以定义PDF_MARGIN_TOP
常量,也可以显式设置边距:
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
回答by essesse
I had the same problem, but solved it by setting the margins with
我遇到了同样的问题,但通过设置边距来解决它
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP-15, PDF_MARGIN_RIGHT);
and
和
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM-15);
so I didn't have to change a defined constant.
所以我不必更改定义的常量。
回答by Vincent
The header itself does not have a height. What you actually want to do is to change the top margin of the main "container". Look in TCPDF config file for:
标题本身没有高度。您真正想要做的是更改主“容器”的上边距。在 TCPDF 配置文件中查找:
define ('PDF_MARGIN_TOP', 19);
Changing the value should solve the problem.
更改值应该可以解决问题。