I am trying to create a simple procedure for signing PDF documents using PHP, openssl and the Zend framework (for unpacking / processing pdf).
I found this one , but it just won’t work, Zend cannot open any PDF files, even Zend pdf tests, and Zend will not tell you why, only that it “cannot”.
I am sure that I can efficiently create keys / certificates, since this is well documented, but is there a strong approach to attaching the generated certificate to a PDF file, since the above Zend extension offers this sometime?
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); }
Editing, adding code: the above only works if I use 'test_pdf2' as the input for Zend_Pdf. It recognizes the certificate as binary, no problem, but I need to be able to transfer the PDF without writing it to disk.
php pdf openssl zend-framework sign
jbrain
source share