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

Asked

Viewed 2,413 times

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 documents, and I saw that the FPDF that I use does not yet support this method, already the TCPDF gives.

As the code is very extensive, I have no way to change to another component. I’ve even been able to access the data of the digital certificate via openssl_pkcs12_read and sign via openssl_sign however do not know how to generate the pdf file containing the certificate information. Someone has an alternative ?

  • Did you get Junior? I’m looking for this too with the A1 certificate.

  • I don’t know if this will help but I found that answer in the English OS

  • I’ve performed this procedure using Java with the iText Library and it worked perfectly. If it fits you can take a look at iText in Action that has examples.

  • Try using http://portablesigner.sourceforge.net/. It’s a java app that you can call from the command line by passing the parameters. We use it to sign the Pdfs.

  • There is no more elaborate answer @Cantoni?

  • Waiting here until the last minute :) Missing 5. :)

  • 1

    @gustavox, I can elaborate an answer, but for this I need to see again how we did it, has long this. At the moment, I lack time. :-)

  • OK @Cantoni, when you get there, and if the community approves (+2 at least) the reward will come in double (pq has to be at least 200 now rsrs, but no problem, I have quite an interest in this subject, and I think it will greatly enrich the community - see positive votes in the question...). Hugs!

Show 3 more comments

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);

Source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.