I am trying to generate and sign pdf using TCPDF library in PHP. The pdf is generated and signed as well but the visible signature is not showing up in anyway.
When opening the pdf in Adobe Viewer, the signature panel appears and reports the signature as valid but the visible signature is not showing up. I want the default signature properties in the visible signature area, like the yellow question mark or green tick.
I am using a commercial signature. I am stuck with this for last 7 days.
public function tcpdf_coo_generation($html,$filename)
{
require_once("tcpdf/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('EEPC India');
$pdf->SetAuthor('EEPC India COO System');
$pdf->SetTitle('Certificate of Origin - Non Preferential');
$pdf->SetSubject('COO');
$pdf->SetKeywords('COO, PDF, EEPC India, Online COO, Engineering Export Promotion');
// set default header data
$pdf->SetHeaderData('', 0, '', '');
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
// 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, 10, 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 (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// set certificate file
//$certificate = 'file://'.$_SERVER['DOCUMENT_ROOT'].'/eepc-rcmc-portal/tcpdf/examples/data/cert/tcpdf.crt';
//$certificate = "file://".$_SERVER['DOCUMENT_ROOT']."/eepc-coo-portal/certs/eepc_cert.pem";
//$privateKey = "file://".$_SERVER['DOCUMENT_ROOT']."/eepc-coo-portal/certs/eepc_key.pem";
$certificate = "file://".$_SERVER['DOCUMENT_ROOT']."/eepc-coo-portal/certs/test-certificates/certificates/alice.crt";
$privateKey = "file://".$_SERVER['DOCUMENT_ROOT']."/eepc-coo-portal/certs/test-certificates/certificates/alice.key";
// set additional information
$info = array(
'Name' => 'EEPC India',
'Location' => 'Office',
'Reason' => 'COO',
'ContactInfo' => 'https://www.eepcindia.org',
);
// set document signature
$pdf->setSignature($certificate, $privateKey, '', '', 2, $info, 'A');
//$pdf->setSignature($certificate, $privateKey, 'tcpdfdemo', '', 2, $info, 'A');
// set font
$pdf->SetFont('helvetica', '', 12);
// add a page
$pdf->AddPage();
// print a line of text
$text = $html;
$pdf->writeHTML($text, true, 0, true, 0);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// *** set signature appearance ***
// create content for signature (image and/or text)
//$pdf->Image('images/signedby-eepcindia-logo.png', 160, 240, 30, 30, 'PNG');
// define active area for signature appearance
$pdf->setSignatureAppearance(160, 240, 30, 30);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// *** set an empty signature appearance ***
//$pdf->addEmptySignatureAppearance(180, 250, 15, 15);
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output($_SERVER['DOCUMENT_ROOT'].'/eepc-coo-portal/uploads/coo_pdfs/'.$filename, 'F');
return true;
}