$pdf = new FPDI();
$filename="Path to the file";
// get the page count
$pageCount = $pdf->setSourceFile($filename);
// iterate through all pages
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
// import a page
$templateId = $pdf->importPage($pageNo);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);
// create a page (landscape or portrait depending on the imported page size)
if ($size['w'] > $size['h']) {
$pdf->AddPage('L', array($size['w'], $size['h']));
} else {
$pdf->AddPage('P', array($size['w'], $size['h']));
}
// use the imported page
$pdf->useTemplate($templateId);
$pdf->SetFont('Helvetica');
$pdf->SetFontSize(8);
$pdf->SetXY(5,0);
$pdf->Write(5, "CSM ROLL NO - $roll_no");
}
// Output the new PDF
$pdf->Output("targetpath",'F');