我目前正在使用TCPDI将四个文档合并为一个PDF,并使用一个变量临时存储该文档。从第三页开始,是否可以在文件中添加“贝茨编号”? (前两页是求职信。)在此先感谢您指出正确的方向
require_once('../tcpdf/tcpdf.php');
require_once('../tcpdf/tcpdi.php');
// Create new PDF document.
$pdf = new TCPDI();
// iterate through the files
foreach ($filesarray AS $file) {
// get the page count
$pageCount = $pdf->setSourceFile($file);
// 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);
// add a page with the same orientation and size
$pdf->AddPage($size['orientation'], $size);
// Set page boxes from imported page 1.
$pdf->setPageFormatFromTemplatePage($pageNo, $size['orientation']);
// use the imported page
$pdf->useTemplate($templateId);
}
}
// Output the new PDF
$attachment = $pdf->Output("Merged.pdf", "S");
答案 0 :(得分:1)
我不熟悉Bates System,但是我所做的是将页码添加为标签,并检查您的PageNo变量/索引以确定何时显示batesNo。
用于标签。请参阅TCPDF文档。
*代码未经测试
<?php
// iterate through the files
foreach ($filesarray AS $file) {
// get the page count
$pageCount = $pdf->setSourceFile($file);
$batesNo = 0000000001; //initialize*****
// 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);
/***********NEW BLOCK*******/
if ($pageNo > 3) {
$pdf->SetTitle('JonesNo-'.$batesNo);
} else {
$pdf->SetTitle($pageNo);
}
////////////////////////
// add a page with the same orientation and size
$pdf->AddPage($size['orientation'], $size);
// Set page boxes from imported page 1.
$pdf->setPageFormatFromTemplatePage($pageNo, $size['orientation']);
// use the imported page
$pdf->useTemplate($templateId);
}
}
?>