我想要能够使用PHP在现有的pdf文档上书写/覆盖文本。我希望做的是有一个pdf文档,可以作为一个模板,并填补空白,打开模板文档,覆盖相关文本,并将结果作为一个新的文档。模板文档是单个页面,因此不需要页面合并/操作。
有没有任何免费的图书馆可以做到这一点?在哪里我应该看?我做的大多数搜索似乎处理合并文档/添加页面,而不是覆盖现有页面上的内容。
谢谢。
*编辑:
这里是我做的:
1.下载FPDF
2.从中下载FPDI FPDF_TPL
以下是任何未来漫游者的示例代码(从www.setasign.de的样本中改编):
include('fpdf.php');
include('fpdi.php');
// initiate FPDI
$pdf =& new FPDI();
// add a page
$pdf->AddPage();
// set the sourcefile
$pdf->setSourceFile('templatedoc.pdf');
// import page 1
$tplIdx = $pdf->importPage(1);
// use the imported page as the template
$pdf->useTemplate($tplIdx, 0, 0);
// now write some text above the imported page
$pdf->SetFont('Arial');
$pdf->SetTextColor(255,0,0);
$pdf->SetXY(25, 25);
$pdf->Write(0, "This is just a simple text");
$pdf->Output('newpdf.pdf', 'D');
?>