I have been working with TCPDF (v6.2.25) for a few days and I am stuck with something that I think is complex. My client needs to print information with some margins on each page using a Multicell (in a textarea). For example, on the first page the margins are $pdf-> SetMargins (32, 44.5, 11); but on the second page the margins are $pdf-> SetMargins (12, 27.5, 29);, because The document he print has more than 3 pages generally (front, back, front) ... sometimes he need to print with the margins in a different order (back, front, etc.) because the paper he use is a government document and he need to follow the order and he can not leave white rows without writing.

My question is, how can I reset the margins in TCPDF on each new page?

Here is my code:

// library
require_once($_SERVER['DOCUMENT_ROOT'] . '/pdf/tcpdf.php');

    define('K_CELL_HEIGHT_RATIO', 2);

    $pdf = new TCPDF('P', 'mm', 'usletter', true, 'UTF-8', false);

    // remove

    // set font
    $pdf->SetFont('times', '', 12);

    // $page is for front or back, this is chosen by my client when he sees the page
    // $line is for the row where the document will start printing, my client chooses the line, the page has only 24 lines where printing is allowed

if($page == 'front'){

    if($line == '1'){ $nline = '44.5'; } 
    if($line == '2'){ $nline = '53'; } 
    if($line == '24'){ $nline = '240'; };

    // set margins(right, top, left);
    $pdf->SetMargins(32, $nline, 11);

    $pdf->SetAutoPageBreak(TRUE, 48);
} else {

    if($line == '1'){ $nline = '27.5'; } 
    if($line == '2'){ $nline = '36'; } 
    if($line == '24'){ $nline = '223'; };

    $pdf->SetMargins(12, $nline, 29); 

    $pdf->SetAutoPageBreak(TRUE, 63.5); 

    $txt = 'document info.....';
    $pdf->Multicell(171, 181, $txt, 0, 'J', 0, 1, '', '', false, 0, true, false, 0);

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

Right now only the first page recognize the $page and the $line in the other pages the margins are the same like the first and the $line too, is the same like the first page and I need that the follow pages reset the margins to line 1 and the top margin to the front or back page according to the corresponding page.

0 Answers