我的服务器上有一堆 pdf,下载时需要将文本附加到每一页。我正在使用 fpdf 尝试打开文件,将文本附加到每个页面,关闭文件并提供给浏览器。
$pdf = new FPDI();
$pdf->setSourceFile($filename);
// import page 1
$tplIdx = $pdf->importPage(1);
//use the imported page and place it at point 0,0; calculate width and height
//automaticallay and ajust the page size to the size of the imported page
$pdf->useTemplate($tplIdx, 0, 0, 0, 0, true);
// now write some text above the imported page
$pdf->SetFont('Arial', '', '13');
$pdf->SetTextColor(0,0,0);
//set position in pdf document
$pdf->SetXY(20, 20);
//first parameter defines the line height
$pdf->Write(0, 'gift code');
//force the browser to download the output
$pdf->Output('gift_coupon_generated.pdf', 'D');
header("location: ".$filename);
此刻,这只是尝试将一些文本放在pdf上的任何位置并保存,但我得到了错误
FPDF error: You have to add a page first!
如果我能做到这一点,那么我需要它将文本附加到文档中的每一页,而不仅仅是 1,不知道如何在阅读文档后执行此操作