How to generate a pdf file containing the digital certificate information? [closed]


I have a PHP system that generates a pdf, and I need to use the client's Digital Certificate to sign this document. I've been reading documentation, and I've seen that the FPDF that I'm using does not yet support this method, since TCPDF gives.

As the code is too long, I can not switch to another component. I have even been able to access the digital certificate data via openssl_pkcs12_read and sign via openssl_sign but I do not know how to generate the pdf file containing the certificate information. Does anyone have an alternative?

asked by anonymous 13.05.2015 / 03:29

1 answer


How to sign pdf created with FPDF, instead of TCPDF


// crie uma instância do FPDF
$pdf = new fpdf();
$pdf->SetFont('Arial', 'B', 14);

// escreva algum conteúdo
$text = 'This document is created with FPDF on '
    . date('r')
    . ' and digital signed with the SetaPDF-Signer component.';
$pdf->MultiCell(0, 8, $text);

// Configura a saída do documento para ser string
$fpdf = $pdf->Output('', 'S');

// or if you use composer require_once('vendor/autoload.php');

// crie um Http writer
$writer = new SetaPDF_Core_Writer_Http('fpdf-sign-demo.pdf', true);
// carregue o documento pelo seu caminho
$document = SetaPDF_Core_Document::loadByString($fpdf, $writer);

// crie uma instância da assinatura para o documento
$signer = new SetaPDF_Signer($document);

// configure algumas propriedades da assinatura
$signer->setReason('Demo with FPDF');

// crie uma instância OpenSSL
$module = new SetaPDF_Signer_Signature_Module_OpenSsl();
// configure o certificado de assinatura
// configura a chave privada para o certificado de assinatura
$module->setPrivateKey(array(file_get_contents('private-key.pem'), 'password'));

// assine o documento


08.10.2016 / 02:28