微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 TCPPDF 和 PHP 在 pdf 中显示数字签名?

如何解决如何使用 TCPPDF 和 PHP 在 pdf 中显示数字签名?

我正在尝试使用 PHP 和 TCPDF 库对 PDF 文件进行数字签名。当我生成 PDF 时,问题就出现了,因为它不会让我看到签名。我设法做的就是创建一个框来使用 Adob​​e Reader 签名。但我的想法不是这样,而是生成PDF文件,直接嵌入签名,不需要任何其他程序。

我使用的代码如下:

<?PHP
//Incluimos los archivos de la libreria tcpdf
require_once('tcpdf/TCPDF-main/examples/tcpdf_include.PHP');
require_once ('tcpdf/TCPDF-main/tcpdf.PHP');


// creamos el documento PDF
$pdf = new TCPDF(PDF_PAGE_ORIENTATION,PDF_UNIT,PDF_PAGE_FORMAT,true,'UTF-8',false);



// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Ivan Martinez');
$pdf->SetTitle('Prueba HolaMundo');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF,PDF,example,test,guide');

// Encabezado de serie
//$pdf->SetHeaderData(PDF_HEADER_logo,PDF_HEADER_logo_WIDTH,PDF_HEADER_TITLE.' 001',PDF_HEADER_STRING,array(0,64,255),128));
//$pdf->setFooterData(array(0,0),128));

// 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,PDF_MARGIN_TOP,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 certificated file
$certificate = 'file://'.realpath('tcpdf.crt');

// set additional information
$info = array(
    'Name' => 'PruebaIvan','Location' => 'Ayuntamiento','Reason' => 'Testeando firma',);


$pdf->setSignature($certificate,$certificate,'tcpdfdemo',2,$info);

// set default font subsetting mode
$pdf->setFontSubsetting(true);

// Set font
// dejavusans is a UTF-8 Unicode font,if you only need to
// print standard ASCII chars,you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans',14,true);


// Add a page
// This method has several options,check the source code documentation for more information.
$pdf->AddPage();

// set text shadow effect
$pdf->setTextShadow(array('enabled'=>true,'depth_w'=>0.2,'depth_h'=>0.2,'color'=>array(196,196,196),'opacity'=>1,'blend_mode'=>'normal'));

// Set some content to print
$html = <<<EOD
Documento creado por Ivan Martinez;
EOD;

// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0,$html,1,true);


$pdf->setSignatureAppearance(200,170,40,20);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// *** set an empty signature appearance ***
$pdf->addEmptySignatureAppearance(180,80,15,15);


// ---------------------------------------------------------

// Close and output PDF document
// This method has several options,check the source code documentation for more information.
$pdf->Output('pruebaFirma.pdf','D');

?>

我曾尝试删除句子 $pdf->addEmptySignatureAppearance(180,15);,但没有用。

提前致谢,问候。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。