由于我找不到将签名作为按钮应用到 pdf 的方法,我不得不摆弄和破解以将所有表单数据和签名从服务器获取到新的 pdf 上。
首先 fopen/f 将表单值写入新的 fdf,然后使用 pdftk 生成一个未签名的 pdf:
echo exec("cd $submissions_path/; $pdftk \"$template\" fill_form \"$fdf\" output \"$unsigned_pdf\"; chmod 777 \"$unsigned_pdf\";");
然后 fopen/fwrite 我的 base64 签名到签名图像:
$fp=fopen("$submissions_path/$simg","wb");
fwrite($fp,base64_decode($scode));
fclose($fp);
然后使用 mPDF 生成要转换为水印 .pdf 的 .html 水印(请原谅使用表格,mPDF 不喜欢我<div>
的):
$watermark_pdf="InstallOrder_{$submissionID}_Watermark.pdf";
$watermark_html="<table style=\"width:792px;height:1123px;\"><tr>";
$watermark_html.="<td colspan=\"2\" style=\"padding-top:900px;padding-left:70px;width:240px;height:20px;\">{$watermark[CustomerSignature]}</td>";
$watermark_html.="</tr><tr>";
$watermark_html.="<td style=\"padding-top:16px;padding-left:69px;width:240px;height:20px;\">{$watermark[OwnerSignature]}</td>";
$watermark_html.="<td style=\"padding-top:16px;padding-left:169px;width:240px;height:20px;\">{$watermark[ManagerSignature]}</td>";
$watermark_html.="</tr></table>";
include("../mpdf/mpdf.php"); //Include mPDF Class
$mpdf=new mPDF('','',0,'',0,0,0,0,0,0,'P'); // Create new mPDF Document
$mpdf->WriteHTML($watermark_html);
$mpdf->Output("$watermark_pdf","F"); //save file to server - may include a path
最后,再次使用 pdftk 将 watermark.pdf 标记到 unsigned.pdf 上:
echo exec("cd $submissions_path/; $pdftk \"$unsigned_pdf\" stamp \"$watermark_pdf\" output \"$pdf\"");
最繁琐的部分是正确设置水印html上签名图像的大小和位置。