Your problem is that you're calling methods for FPDI in the wrong order. Here are the steps to take:
- Import the page you want to modify, get the template
- Add a new blank page to the document
- Load the template into that document
- Write additional content to that document
Here is a brief code example illustrating the above concept. I have tested this and gotten the output expected.
$pdf = new FPDI();
$pageCount = $pdf->setSourceFile('file.pdf');
// Iterate through every page
for( $pageNo=1; $pageNo<=$pageCount; $pageNo++ )
{
// Import page
$templateId = $pdf->importPage($pageNo);
$pdf->getTemplateSize($templateId);
$pdf->addPage('P');
$pdf->useTemplate($templateId);
// Modify page
$pdf->SetFont('Arial');
$pdf->SetTextColor(0,0,0);
$pdf->SetFontSize(8);
$pdf->Text(50,124,"Emp Name : Sanjay Singh");
}
$pdf->Output("upload/new_linebreak_pdf.pdf", "F");