我正在尝试使用PHP、openssl和Zend框架(用于PDF再现/处理)构建一个简单的pdf文档签名例程。
我已经找到了this,但它根本不能工作,Zend无法打开任何pdf,甚至Zend自己的测试pdf,Zend也不会报告原因,只是说它“不能”。
我非常确定我能够有效地创建密钥/证书,因为这是很好的文档,但是有没有像上面的Zend扩展建议的那样将生成的证书附加到PDF的可靠方法?
function DigiSignPDF ($pdf_sign_request) {
if (get_magic_quotes_gpc()) {
$new_pdf = stripslashes($pdf_sign_request['raw_pdf']);
} else {
$new_pdf = $pdf_sign_request['raw_pdf'];
}
$test_pdf = stripslashes(file_get_contents('path/Some.pdf'));
$test_pdf2 = ('path/Some.pdf');
$pdf = Zend_Pdf::load($new_pdf2);
//below is the signing code, from another library, it works as long as Zend_Pdf works
$certificate = file_get_contents('path/certificate.p12');
$certificatePassword = 'test123';
if (empty($certificate)) {
throw new Zend_Pdf_Exception('Cannot retrieve/generate the certificate.');
}
$pdf->attachDigitalCertificate($certificate,$certificatePassword);
$eSig_pdf = $pdf->render();
file_put_contents('path/signed_pdf.pdf', $eSig_pdf);
}
编辑,添加代码:仅当我使用'test_pdf2‘作为Zend_Pdf的输入时,上述方法才有效。它将证书识别为二进制,没有问题,但我需要能够传递PDF,而不需要将其写入磁盘。
发布于 2012-06-08 20:11:57
添加我的解决方案作为答案,per halfer的建议:解决了这个问题,因为我将内容作为字符串传递给Zend_Pdf,所以我应该使用Zend_Pdf::parse($new_pdf);,正如手册中很可能会说的那样。(糟糕)
此外,正如这里的几篇文章所建议的那样,我通过迁移到TCPDF解决了几乎所有关于对各种版本和表单的PDF进行数字签名的问题。TCPDF也遇到了类似的警告,但在使用字符串时,请确保使用的是TCPDF的'writeHTMLCell‘而不是'writeHTML’。注意PHP的‘magic’、错误的空格、编码和goblins。
https://stackoverflow.com/questions/10903682
复制相似问题