dtdr57046 2014-06-27 10:04 采纳率: 100%
浏览 39
已采纳

如何将用户的签名从webform转移到pdf模板?

I have a web form that uses an HTML5 canvas element to allow users to sign their name. When the form is submitted, all field values and the base64 string (e.g. "data:image/png;base64,blahblahetc") containing the user's signature are processed and stored.

I'd like to fill my pdf template with the submitted data and write the signature to the form but I am struggling with the signature task.

I found one technique while researching that suggests I could write the signature as a pdf button using:

<< /T (button1)/APRef << /N << /F (http://www.yoursite.com/pfds/icons.pdf)/Name (icon3)>> >> >> 

However, I can't manage to get this to work. I don't know if the signature must be prepared as .png, .pdf, or something else. (I can successfully generate a .png on the server, but haven't tried to apply it to the .pdf because I don't know if I need it.)

I am using pdftk to fill my template .pdf with the dynamic .fdf file. Do I need to perform any special preparations on the signature button? I think I read something about setting the Layout to "Icon Only."

  • 写回答

1条回答 默认 最新

  • dtu15253 2014-09-30 13:51
    关注

    Since I could not find a way to apply the signature to the pdf as a button, I had to fiddle and hack to get all form data and signatures from the server onto a new pdf.

    First fopen/fwrite the form values to new fdf, then use pdftk to generate an unsigned pdf:

    echo exec("cd $submissions_path/; $pdftk \"$template\" fill_form \"$fdf\" output \"$unsigned_pdf\"; chmod 777 \"$unsigned_pdf\";");
    

    Then fopen/fwrite my base64 signatures to signature images:

    $fp=fopen("$submissions_path/$simg","wb");
    fwrite($fp,base64_decode($scode));
    fclose($fp);
    

    Then generate an .html watermark to be converted to a watermark .pdf using mPDF (please excuse the use of tables, mPDF didn't like my <div>'s):

    $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
    

    Finally, stamp the watermark.pdf onto the unsigned.pdf using pdftk again:

    echo exec("cd $submissions_path/; $pdftk \"$unsigned_pdf\" stamp \"$watermark_pdf\" output \"$pdf\"");
    

    The most tedious part is correctly setting the size and position of the signature images on the watermark html.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c