TCPDF SetMargins method


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->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.

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);
//your HTML code here ...

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