我有大量的pdf。每个pdf包含许多页面。我必须在现有pdf的每一页中添加一个页脚。
现在请建议如何获得。文件中的页面以及如何循环它们并在每个页面上添加页脚?
答案 0 :(得分:0)
$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');