【发布时间】:2014-07-31 15:27:37
【问题描述】:
我一直坚持使用 fpdf 和 fpdi。
我正在使用此代码从 5 个或更多文件 (!important) 创建 1 个 pdf 文件,并希望在每个页面上输入唯一的文本。当前形式的代码将 page01test 放在每个页面上,而不是 page02test 放在第 2 页等上。
每个导入的文档由一页组成。
此代码的基础来自:http://www.setasign.com/products/fpdi/demos/concatenate-fake/
require('fpdf.php');
require('fpdi.php');
class ConcatPdf extends FPDI
{
public $files = array();
public function setFiles($files)
{
$this->files = $files;
}
public function concat()
{
foreach($this->files AS $file) {
$pageCount = $this->setSourceFile($file);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
$tplIdx = $this->ImportPage($pageNo);
$this->AddPage();
$this->useTemplate($tplIdx);
$this->AddFont('NotoSans', '', 'notosans.php');
$this->SetFont('NotoSans', '', 18);
$this->SetTextColor(63,76,89);
if ($pageNo == 1) {
$this->SetXY(55, 94);
$this->Write(5, 'page01test');
}
if ($pageNo == 2) {
$this->SetXY(55, 94);
$this->Write(5, 'page02test');
}
if ($pageNo == 3) {
$this->SetXY(55, 94);
$this->Write(5, 'page03test');
}
if ($pageNo == 4) {
$this->Write(5, 'page04test');
}
if ($pageNo == 5) {
$this->SetXY(55, 94);
$this->Write(5, 'page05test');
}
}
}
}
}
$pdf = new ConcatPdf();
$pdf->setFiles(array("Proposal1.pdf", "Proposal2.pdf","Proposal3.pdf", "Proposal4.pdf","Proposal5.pdf"));
$pdf->concat();
$pdf->Output();
【问题讨论】:
-
您有什么问题吗?
-
对不起,我没有意识到我没有说得很清楚。它不能以当前的形式工作,我想知道如何更改代码以使每个页面上的文本都是唯一的,因此第 1 页上的 page01test、第 2 页上的 page02test 等等。
-
代码看起来“正常”...您确定不是缓存问题吗?尝试通过向 URL 添加随机获取参数来强制浏览器加载新版本。
-
添加获取参数时也不起作用。我被难住了……