'TCPDF 1st page Missing on Import Page

When I try to import a pdf from an existing pdf it removes the first page and starts from the second. where am I going wrong

 $pdf = new TcpdfFpdi('P', 'mm', 'A4', true, 'UTF-8', false, true);
                       
 $pdf->SetCreator('TCPDF Name');
 $pdf->SetAuthor('TCPDF Author');
 $pdf->SetTitle('TCPDF title');
 $pdf->SetSubject('TCPDF Tutorial');
 $pdf->SetKeywords('KEYWORDS');

                      
 $pagecount = $pdf->setSourceFile('/** file path**/');

  for ($i=1; $i<=$pagecount; $i++) {

       $tplId = $pdf->importPage($i);
       $pdf->useTemplate($tplId,0,0,'210','297');

        if ($i < $pagecount)
            $pdf->AddPage('P','A4');
         }

  $pdf->Output(public_path('filename'.pdf'), 'F');


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source