TCPDF SetMargins method

tcpdf

I'm working to get exact positioning in tcpdf. I'm trying to use SetMargins() in multiple places, but I must be misunderstanding the usage of this method.
It doesn't seem to be working as I expect.

$pdf->SetFont('helvetica', '', 12);
$pdf->AddPage();
$pdf->SetMargins(10, 10, 10, true); // set the margins 

$html = 'Here is some text';

$pdf->writeHTMLCell(0, 0, '', '', $html, 'LRTB', 1, 0, true, 'L', true); 

$pdf->SetMargins(0, 10, 0, true); // put space of 10 on top 

$pdf->writeHTMLCell(0, 0, '', '', $html, 'LRTB', 1, 0, true, 'C', true);
$pdf->writeHTMLCell(0, 0, '', '', $html, 'LRTB', 1, 0, true, 'R', true);      

$pdf->Output('example_002.pdf', 'I');

I'm definitely getting an output, but I'm expecting the first and second writeHTMLCell() to have the space reset between them.

http://www.tcpdf.org/doc/classTCPDF.html#ab3bbdb7c85ea08d175fd559be6132ba0

The documentation says the second parameter is for top margin.

In short, I want to mess with margins for each line, if necessary. But I may be using the wrong method for this.
My example above seems to be ignoring that parameter entirely. But it doesn't seem to have a problem with the left and right parameters.

Best Solution

The TCPDF SetMargins method is:

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

So you can use it before AddPage(); method like below:

$pdf->SetMargins(10, 20, 10, true);
$pdf->AddPage();
//your HTML code here ...

$keepmargins(boolean) if true overwrites the default page margins.