【发布时间】:2016-10-20 07:04:30
【问题描述】:
我有大量的 pdf。每个 pdf 包含许多页面。我必须在现有 pdf 的每一页中添加页脚。
- 导入文件后怎么知道pdf有多少页?
- 我可以创建一个在每个页面上自动调用的函数吗?
现在请建议如何拒绝。文件中的页面数以及如何循环它们并在每页上添加页脚?
【问题讨论】:
我有大量的 pdf。每个 pdf 包含许多页面。我必须在现有 pdf 的每一页中添加页脚。
现在请建议如何拒绝。文件中的页面数以及如何循环它们并在每页上添加页脚?
【问题讨论】:
$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');
【讨论】: