add Digital Signature using mPDF object

2019-08-14 22:28发布

I'm using mPDF to create a PDF. I want to digitally add a signature to the PDF document.

I can only find online examples for adding a digital signature to a tcPDF object, not an mPDF.

Does anyone have any information on the subject that can help me?

This is my PHP code:

$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");

Thank you so much!

1条回答
冷血范
2楼-- · 2019-08-14 22:47

Edit (17.05.14):

I had found the next library - here (scroll down) and made some use of it by packing it with the right Zend libraries to make it work out of the box. So if you want to digitally sign a PDF using PHP you can use the next lib. http://www.mediafire.com/download/181rgs86nvr4nd5/signPdf.zip

After several weeks of looking for a PHP solution for signing already generated PHP file this is the only working with good performance solution that I had found, it can be used with any PDF library.

Thanks for Damir for developing this lib.


Old obsolete answer
I am struggling with the same problem as well. The only solution I had found for now is to create the PDF then use https://www.setasign.com/products/fpdi/about/#p-510 to import the PDF into TCPDF.

and then sign it with TCPDF.

first create a class then inherit from fpdi and TCPDF

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

then do the actual signing

$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');

I had tried to use TCPDF signing algorithm and use it in mPdf but failed to do it, so if someone succeed some how I'll be happy to know!

查看更多
登录 后发表回答