我有一个使用HTML5 canvas元素的Web表单,允许用户签名。提交表单时,将处理并存储包含用户签名的所有字段值和base64字符串(例如“data:image / png; base64,blahblahetc”)。
我想用提交的数据填写我的pdf模板并将签名写入表单,但我正在努力完成签名任务。
我在研究时发现了一种技术,这表明我可以使用以下命令将签名编写为pdf按钮:
<< /T (button1)/APRef << /N << /F (http://www.yoursite.com/pfds/icons.pdf)/Name (icon3)>> >> >>
但是,我无法让这个工作。我不知道签名是否必须准备为.png,.pdf或其他东西。 (我可以在服务器上成功生成.png,但是没有尝试将它应用到.pdf,因为我不知道是否需要它。)
我使用pdftk用动态.fdf文件填充我的模板.pdf。我是否需要在签名按钮上执行任何特殊准备工作?我想我已经阅读了一些关于将布局设置为“仅图标”的内容。
答案 0 :(得分:2)
由于我找不到将签名作为按钮应用于pdf的方法,因此我不得不小心翼翼地将服务器上的所有表单数据和签名都添加到新的pdf中。
首先fopen / fwrite表格值为新的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);
然后生成.html水印,使用mPDF转换为水印.pdf(请原谅使用表格,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上正确设置签名图像的大小和位置。