php TCPDF 页边距问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9431973/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 06:48:22  来源:igfitidea点击:

TCPDF Page Margin Issue

phpmargintcpdfmargins

提问by Revenant

I'm creating PDF files with PHP using TCPDF. I have a small problem with created PDF files. I would like to set up right and left margin of each PDF file created. Currently if there is 10px margin on the left side, there is 20px margin on the right side.

我正在使用 TCPDF 用 PHP 创建 PDF 文件。我对创建的 PDF 文件有一个小问题。我想设置创建的每个 PDF 文件的左右边距。目前如果左边有10px的边距,右边有20px的边距。

How do I set up right and left page margin?

如何设置左右页边距?

Thank you all for your time and concern.

感谢大家的时间和关心。

I tried following;

我试过跟随;

$pdf->SetMargins(10, 10, -50, true);and $pdf->SetRightMargin(-50);without any luck.

$pdf->SetMargins(10, 10, -50, true);$pdf->SetRightMargin(-50);没有任何的运气。

回答by Jeremy Harris

In the new documentationit shows the function as

新文档中,它将函数显示为

TCPDF::SetMargins($left,$top,$right = -1,$keepmargins = false)

TCPDF::SetMargins($left,$top,$right = -1,$keepmargins = false)

And describes the parameters as:

并将参数描述为:

Parameters:

$left   (float) Left margin.
$top    (float) Top margin.
$right  (float) Right margin. Default value is the left one.
$keepmargins    (boolean) if true overwrites the default page margins

参数:

$left   (float) Left margin.
$top    (float) Top margin.
$right  (float) Right margin. Default value is the left one.
$keepmargins    (boolean) if true overwrites the default page margins

So, for the right margin a -1is used to indicate that no right margin was supplied and to use the same as the left margin. You were using -50which is not a valid margin.

因此,对于右边距,a-1用于表示没有提供右边距,并使用与左边距相同的值。您使用的-50是无效保证金。

Try this instead:

试试这个:

$pdf->SetMargins(10, 10, 10, true);