duan198811 2019-05-22 18:13
浏览 186

由TCPDF生成和签名的PDF不显示可见签名

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;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器