2013-04-19 17 views
5

Ho un problema strano.
Ho difficoltà con un problema di firma digitale pdf da un po 'e non funzionava come previsto. In realtà non funziona affatto.

Ho usato exacly stesso codice è pubblicato nella pagina Examples 52:TCPDF aggiunta di firma digitale al pdf creato

// set certificate file 
$certificate = 'file://var/www/app/tcpdf/config/cert/tcpdf.crt'; 

// set additional information 
$info = array(
    'Name' => 'TCPDF', 
    'Location' => 'Office', 
    'Reason' => 'Testing TCPDF', 
    'ContactInfo' => 'http://www.tcpdf.org', 
    ); 

// set document signature 
$pdf->setSignature($certificate, $certificate, 'tcpdfdemo', '', 2, $info); 

Il primo problema era di circa

Warning: openssl_pkcs7_sign() [function.openssl-pkcs7-sign]: error getting private key in /var/www/app/tcpdf/tcpdf.php on line 7566 

E 'stato causato perché non ho impostato i privilegi per eseguire cert directory. Ma dopo ho impostato la magia 777.
Da ora in poi non vedo che cosa è l'errore, e non vedo la pista errore, ma:

HTTP ERROR 324 (net::ERR_EMPTY_RESPONSE) 

Qualcuno mi può suggerire qualcosa?

+0

Sembra che il tuo errore non sia più l'utilizzo delle funzionalità di firma di tcpdf. Non vedo nulla nel tuo codice per mostrare che stai trasmettendo il pdf firmato al browser. Lo stai facendo? In caso contrario, la tua risposta sarà vuota e probabilmente causerà quell'errore. –

+0

Puoi mostrarmi qualche esempio di cose che scrivi? se intendi quelle righe '$ pdf-> Immagine ('../ images/tcpdf_signature.png', 180, 60, 15, 15, 'PNG'); $ PDF-> setSignatureAppearance (180, 60, 15, 15); 'ho provato senza successo – Mithrand1r

+0

Soprattutto, non vedo nel codice postato qui una chiamata a $ pdf-> Output ('name'. pdf ',' I '); 'per inviare effettivamente il pdf al browser. La funzione di uscita ha molte opzioni per salvare o inviare il pdf documentato in [link] (http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1) –

risposta

9

Da quello che vedo, l'errore che stai ricevendo non è causato dal codice che hai inserito nella tua domanda in quanto quel codice è straignforward ed esattamente come quello trovato nella documentazione di TCPDF. È possibile trovare un esempio di invio di un file PDF firmato a TCPDF Documentation

Il codice non è la seguente:

require_once('../config/lang/eng.php'); 
require_once('../tcpdf.php'); 

// create new PDF document 
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 

// set document information 
$pdf->SetCreator(PDF_CREATOR); 
$pdf->SetAuthor('Nicola Asuni'); 
$pdf->SetTitle('TCPDF Example 052'); 
$pdf->SetSubject('TCPDF Tutorial'); 
$pdf->SetKeywords('TCPDF, PDF, example, test, guide'); 

// set default header data 
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 052', PDF_HEADER_STRING); 

// set header and footer fonts 
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); 
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); 

// set default monospaced font 
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); 

//set margins 
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); 
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); 
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER); 

//set auto page breaks 
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); 

//set image scale factor 
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 

//set some language-dependent strings 
$pdf->setLanguageArray($l); 

// --------------------------------------------------------- 

/* 
NOTES: 
- To create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt 
- To export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12 
- To convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes 
*/ 

// set certificate file 
$certificate = 'file://../config/cert/tcpdf.crt'; 

// set additional information 
$info = array(
    'Name' => 'TCPDF', 
    'Location' => 'Office', 
    'Reason' => 'Testing TCPDF', 
    'ContactInfo' => 'http://www.tcpdf.org', 
    ); 

// set document signature 
$pdf->setSignature($certificate, $certificate, 'tcpdfdemo', '', 2, $info); 

// set font 
$pdf->SetFont('helvetica', '', 12); 

// add a page 
$pdf->AddPage(); 

// print a line of text 
$text = 'This is a <b color="#FF0000">digitally signed document</b> using the default (example) <b>tcpdf.crt</b> certificate.<br />To validate this signature you have to load the <b color="#006600">tcpdf.fdf</b> on the Arobat Reader to add the certificate to <i>List of Trusted Identities</i>.<br /><br />For more information check the source code of this example and the source code documentation for the <i>setSignature()</i> method.<br /><br /><a href="http://www.tcpdf.org">www.tcpdf.org</a>'; 
$pdf->writeHTML($text, true, 0, true, 0); 

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// *** set signature appearance *** 

// create content for signature (image and/or text) 
$pdf->Image('../images/tcpdf_signature.png', 180, 60, 15, 15, 'PNG'); 

// define active area for signature appearance 
$pdf->setSignatureAppearance(180, 60, 15, 15); 

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

// *** set an empty signature appearance *** 
$pdf->addEmptySignatureAppearance(180, 80, 15, 15); 

// --------------------------------------------------------- 

//Close and output PDF document 
$pdf->Output('example_052.pdf', 'I'); 

Si noti che, è necessario aggiungere le pagine al documento e quindi chiamare la funzione di uscita() in per ottenere effettivamente l'output inviato al browser. Altrimenti, il server non avrà alcun dato da inviare e quindi ti darà una risposta vuota causando questo errore.

Questo errore può anche essere causato se si sta creando il file sul server e salvandolo in una cartella in cui lo script non dispone delle autorizzazioni per accedere e stampare sul browser.

Se si utilizza Google Chrome per visualizzare i file PDF, si potrebbe desiderare di controllare le informazioni qui su questo errore Chrome Empty Response Errors Group

Inoltre, ci sono rapporti che questo errore è stato causato da configurato in modo errato Zend Optimizer/Zend Impostazioni del guardiano. Se nessuno dei precedenti è il caso, farei in modo che questi siano disattivati ​​per continuare la risoluzione dei problemi.

Come si può vedere, questo errore è un po 'non specifico e quindi può essere difficile da risolvere.

+0

Qualche idea su come aggiungere un timestamp alla firma? applyTSA non è implementato nella libreria :( – h2odev