phptcpdffpdi

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');

Solution

  •     $pdf = new TcpdfFpdi('P', 'mm', 'A4', true, 'UTF-8', false, true);
    
       $pages = $pdf->setSourceFile($this->file->path());
         for ($i=1; $i<=$pages; $i++)
            {
               $pdf->AddPage();
               $tplIdx = $pdf->importPage($i);
               $pdf->useTemplate($tplIdx, 0, 0, '210','297');
           }
        $pdf->Output(public_path('filename'.pdf'), 'F');