Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCPDF Page Margin Issue

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.

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.

like image 559
Revenant Avatar asked Feb 24 '12 14:02

Revenant


1 Answers

In the new documentation it shows the function as

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

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

Try this instead:

$pdf->SetMargins(10, 10, 10, true);
like image 165
Jeremy Harris Avatar answered Oct 31 '22 20:10

Jeremy Harris