0

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');
Olivier
  • 13,283
  • 1
  • 8
  • 24
S P
  • 1
  • 2

1 Answers1

0
    $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');
S P
  • 1
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 12 '22 at 21:26