我正在尝试使用PHP、openssl和Zend框架(用于PDF渲染/处理)构建一个简单的PDF文档签名例程。
我找到了这个,但它根本无法工作,Zend无法打开任何PDF文件,甚至不能打开自己的测试PDF文件,并且Zend不会报告原因,只是说它“无法”。
我相当确定我能够有效地创建密钥/证书,因为这已经有很好的文档支持,但是否有一种可靠的方法将生成的证书附加到PDF中,就像上面的Zend扩展曾经建议过的那样?
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而无需将其写入磁盘。