Php – margins in TCPDF when using writeHTML()

PHPtcpdf

I am trying to create a PDF using TCPDF library. I have some problem with table written with method writeHTML() though. When table has to many rows, the rest of it is moved to the next page. Its proper behavior, but I need to to have some top margin on this new page. However TCPDF is making only default margin, which is to small in my case. Ive tried to use setMargins(), setXY() but nothing seems to work. It even looks like general margins of PDF has no influcence on content created by writeHTML(). Anyone had similar problem?

Best Answer

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);
Related Topic