使用mPDF对象添加数字签名 [英] add Digital Signature using mPDF object

查看:278
本文介绍了使用mPDF对象添加数字签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我只能在网上找到将数字签名添加到tcPDF对象而不是mPDF的示例.

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?

这是我的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");

非常感谢您!

推荐答案

编辑(17.05.14):

我找到了下一个库- http://www.mediafire.com/download/181rgs86nvr4nd5/signPdf.zip

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

在寻找一个用于签名已经生成的PHP文件的PHP解决方案几周之后,这是我发现的唯一一种具有良好性能的解决方案,可以与任何PDF库一起使用.

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.

感谢达米尔(Damir)开发了这个库.

Thanks for Damir for developing this lib.

过时的答案
我也在同一个问题上挣扎. 我目前发现的唯一解决方案是创建PDF,然后使用 https://www.setasign.com/products/fpdi/about/#p-510 将PDF导入TCPDF.

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.

,然后使用TCPDF签名.

and then sign it with TCPDF.

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

first create a class then inherit from fpdi and 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中使用它,但未能成功,所以如果有人成功了,我将很高兴知道!

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!

这篇关于使用mPDF对象添加数字签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆