我希望能够使用PHP在现有的pdf文档上编写/覆盖文本.我希望做的是拥有一个可以充当模板的pdf文档,并通过打开模板文档,覆盖相关文本并将结果作为新文档提供来填补空白.模板文档是单个页面,因此不需要页面合并/操作.
有没有可以做到这一点的免费图书馆?在哪里我应该看?我所做的大多数搜索似乎都处理合并文档/添加页面,而不是在现有页面上覆盖内容.
谢谢.
*编辑:这是我做的:1.下载FPDF 2.下载FPDI + FPDF_TPL
http://www.setasign.de/products/pdf-php-solutions/fpdi/downloads/
以下是任何未来流浪者的示例代码(改编自www.setasign.de上的样本):
<?php
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');
?>
Run Code Online (Sandbox Code Playgroud)