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

18

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

0

How to sign pdf created with FPDF, instead of TCPDF

<?php
require_once('fpdf.php');

// crie uma instância do FPDF
$pdf = new fpdf();
$pdf->AddPage();
$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');

require_once('library/SetaPDF/Autoload.php');
// 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');
$signer->setLocation('setasign.com');

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

// assine o documento
$signer->sign($module);

Font

    
08.10.2016 / 02:28