首页 文章

使用mPDF对象添加数字签名

提问于
浏览
1

我正在使用mPDF来创建PDF . 我想以数字方式将签名添加到PDF文档中 .

我只能找到向tcPDF对象添加数字签名的在线示例,而不是mPDF .

有没有人有关于这个问题的任何信息可以帮助我?

这是我的PHP代码:

$pdf=new mPDF('en','A4','','DejaVuSansCondensed',$template->margin_left,$template->margin_right,$template->margin_top,$template->margin_bottom,$template->margin_header,$template->margin_footer);

$pdf->setAutoFont();
$pdf->SetHTMLHeader($header);
$pdf->SetHTMLFooter($footer);
$pdf->writeHTML($printable);

$pdf->Output($file_name, "D");

非常感谢!

1 回答

  • 1

    Edit (17.05.14):

    我找到了next library - here(向下滚动)并通过使用正确的Zend库打包它来使用它,使其开箱即用 . 因此,如果您想使用PHP对PDF进行数字签名,则可以使用下一个库 . http://www.mediafire.com/download/181rgs86nvr4nd5/signPdf.zip

    在寻找用于签署已生成的PHP文件的PHP解决方案数周之后,这是唯一使用我找到的性能良好的解决方案,它可以用于任何PDF库 .

    感谢Damir开发这个lib .


    Old obsolete answer
    我也在努力解决同样的问题 . 我现在找到的唯一解决方案是创建PDF然后使用https://www.setasign.com/products/fpdi/about/#p-510将PDF导入TCPDF .

    然后使用TCPDF进行签名 .

    首先创建一个类然后从fpdi和TCPDF继承

    require_once('tcpdf.php');
    require_once('fpdi.php');
    class Signpdf_lib extends FPDI{}
    

    然后进行实际签名

    $pdfSigner = new Signpdf_lib();
    $pageCount = $pdfSigner->setSourceFile($this->pdfFilePath);
    // iterate through all pages
    for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
        // import a page
        $templateId = $pdfSigner->importPage($pageNo);
       // get the size of the imported page
       $size = $pdfSigner->getTemplateSize($templateId);
       // create a page 
       $pdfSigner->AddPage('P', array($size['w'], $size['h']));
      // use the imported page
        $pdfSigner->useTemplate($templateId);
    }
    $info = array(
        'Name' => "$documentName - $documentNumber",
        'Location' => 'IL',
        'Reason' => 'DOC SIGN',
        'ContactInfo' => 'user details',
    );
    //load the certificate
    $certificateStr = Signatures_lib::loadSignature();
    // set document signature
    $pdfSigner->setSignature($certificateStr, null, null, null, 1, $info);
    // define active area for signature appearance
    $pdfSigner->setSignatureAppearance(0, 5, 30, 30);
    $pdfSigner->Output($this->pdfFilePath, 'F');
    

    我曾尝试使用TCPDF签名算法并在mPdf中使用但未能成功,所以如果有人成功了,我会很高兴知道!

相关问题