本文实例讲述了php实现往pdf中加数字签名操作。分享给大家供大家参考,具体如下:

//============================================================+

// file name : example_052.php

// begin : 2009-05-07

// last update : 2013-05-14

//

// description : example 052 for tcpdf class

// certification signature (experimental)

//

// author: nicola asuni

//

// (c) copyright:

// nicola asuni

// tecnick.com ltd

// www.tecnick.com

// info@tecnick.com

//============================================================+

/**

* creates an example pdf test document using tcpdf

* @package com.tecnick.tcpdf

* @abstract tcpdf - example: certification signature (experimental)

* @author nicola asuni

* @since 2009-05-07

*/

// include the main tcpdf library (search for installation path).

require_once('tcpdf_include.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(pdf_creator);

$pdf->setauthor('nicola asuni');

$pdf->settitle('tcpdf example 052');

$pdf->setsubject('tcpdf tutorial');

$pdf->setkeywords('tcpdf, pdf, example, test, guide');

// set default header data

$pdf->setheaderdata(pdf_header_logo, pdf_header_logo_width, pdf_header_title.' 052', pdf_header_string);

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

}

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

/*

notes:

- to create self-signed signature: openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout tcpdf.crt -out tcpdf.crt

- to export crt to p12: openssl pkcs12 -export -in tcpdf.crt -out tcpdf.p12

- to convert pfx certificate to pem: openssl pkcs12 -in tcpdf.pfx -out tcpdf.crt -nodes

*/

// set certificate file

$certificate = 'file://data/cert/tcpdf.crt';

$certificate = 'file://'.realpath('./data/cert/tcpdf.crt');

// set additional information

$info = array(

'name' => 'tcpdf',

'location' => 'office',

'reason' => 'testing tcpdf',

'contactinfo' => 'http://www.tcpdf.org',

);

// set document signature

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

// set font

$pdf->setfont('helvetica', '', 12);

// add a page

$pdf->addpage();

// print a line of text

$text = 'this is a digitally signed document using the default (example) tcpdf.crt certificate.
to validate this signature you have to load the tcpdf.fdf on the arobat reader to add the certificate to list of trusted identities.
for more information check the source code of this example and the source code documentation for the setsignature() method.www.tcpdf.org';

$pdf->writehtml($text, true, 0, true, 0);

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

// *** set signature appearance ***

// create content for signature (image and/or text)

$pdf->image('images/tcpdf_signature.png', 180, 60, 15, 15, 'png');

// define active area for signature appearance

$pdf->setsignatureappearance(180, 60, 15, 15);

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

// *** set an empty signature appearance ***

$pdf->addemptysignatureappearance(180, 80, 15, 15);

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

//close and output pdf document

$pdf->output('example_052.pdf', 'd');

//============================================================+

// end of file

//============================================================+

其中tcpdf_include.php文件(源自tcpdf插件)如下:

//============================================================+

// file name : tcpdf_include.php

// begin : 2008-05-14

// last update : 2014-12-10

//

// description : search and include the tcpdf library.

//

// author: nicola asuni

//

// (c) copyright:

// nicola asuni

// tecnick.com ltd

// www.tecnick.com

// info@tecnick.com

//============================================================+

/**

* search and include the tcpdf library.

* @package com.tecnick.tcpdf

* @abstract tcpdf - include the main class.

* @author nicola asuni

* @since 2013-05-14

*/

// always load alternative config file for examples

require_once('config/tcpdf_config_alt.php');

// include the main tcpdf library (search the library on the following directories).

$tcpdf_include_dirs = array(

realpath('../tcpdf.php'),

'/usr/share/php/tcpdf/tcpdf.php',

'/usr/share/tcpdf/tcpdf.php',

'/usr/share/php-tcpdf/tcpdf.php',

'/var/www/tcpdf/tcpdf.php',

'/var/www/html/tcpdf/tcpdf.php',

'/usr/local/apache2/htdocs/tcpdf/tcpdf.php'

);

foreach ($tcpdf_include_dirs as $tcpdf_include_path) {

if (@file_exists($tcpdf_include_path)) {

require_once($tcpdf_include_path);

break;

}

}

//============================================================+

// end of file

//============================================================+

eng.php文件如下:

//============================================================+

// file name : eng.php

// begin : 2004-03-03

// last update : 2010-10-26

//

// description : language module for tcpdf

// (contains translated texts)

// english

//

// author: nicola asuni

//

// (c) copyright:

// nicola asuni

// tecnick.com ltd

// manor coach house, church hill

// aldershot, hants, gu12 4rq

// uk

// www.tecnick.com

// info@tecnick.com

//============================================================+

/**

* tcpdf language file (contains translated texts).

* @package com.tecnick.tcpdf

* @brief tcpdf language file: english

* @author nicola asuni

* @since 2004-03-03

*/

// english

global $l;

$l = array();

// page meta descriptors --------------------------------------

$l['a_meta_charset'] = 'utf-8';

$l['a_meta_dir'] = 'ltr';

$l['a_meta_language'] = 'en';

// translations --------------------------------------

$l['w_page'] = 'page';

//============================================================+

// end of file

//============================================================+

补充:

tcpdf.crt文件点击此处。

tcpdf插件点击此处。

希望本文所述对大家php程序设计有所帮助。

希望与广大网友互动??

点此进行留言吧!

php实现电子签名,php实现往pdf中加数字签名操作示例【附源码下载】相关推荐

  1. 美!视差滚动在图片滑块中的应用【附源码下载】

    视差滚动(Parallax Scrolling)已经被广泛应用于网页设计中,这种技术能够让原本平面的网页界面产生动感的立体效果.下面分享的这个图片滑块效果是难得一见的结合视差滚动的例子,之前的文章给大 ...

  2. 美!视差滚动特效在图片滑块中的应用【附源码下载】

    视差滚动(Parallax Scrolling)已经被广泛应用于网页设计中,这种技术能够让原本平面的网页界面产生动感的立体效果.下面分享的这个图片滑块效果是难得一见的结合视差滚动的例子,之前的文章给大 ...

  3. Web 开发中很实用的10个效果【附源码下载】

    在工作中,我们可能会用到各种交互效果.而这些效果在平常翻看文章的时候碰到很多,但是一时半会又想不起来在哪,所以养成知识整理的习惯是很有必要的.这篇文章给大家推荐10个在 Web 开发中很有用的效果,记 ...

  4. Winforn中DevExpress的TreeList中显示某路径下的所有目录和文件(附源码下载)

    场景 Winform中DevExpress的TreeList的入门使用教程(附源码下载): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/deta ...

  5. 【android-tips】如何在android应用中插入百度广告(附源码)

    (转载请注明出处:http://blog.csdn.net/buptgshengod) 1.介绍    现在游戏中的广告基本上已经成为了游戏创作者的一个重要的收入来源.其实插入广告还是挺简单的,本文选 ...

  6. Winforn中实现ZedGraph自定义添加右键菜单项(附源码下载)

    场景 Winform中实现ZedGraph中曲线右键显示为中文: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100115292 ...

  7. Winform中实现ZedGraph的多条Y轴(附源码下载)

    场景 Winforn中设置ZedGraph曲线图的属性.坐标轴属性.刻度属性: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...

  8. Winform中DevExpress的TreeList的入门使用教程(附源码下载)

    场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...

  9. C#中实现一个TreeGridView(树形表格)附源码下载

    场景 效果 示例源码下载 https://download.csdn.net/download/badao_liumang_qizhi/11593399 实现 新建一个Winform程序,然后在页面上 ...

最新文章

  1. 文章已转移到“字符集编码与乱码”分类下
  2. Windows系统下搭建Git本地代码库
  3. phpMyAdmin ‘tbl_gis_visualization.php’多个跨站脚本漏洞
  4. 大楼通信综合布线系统_建筑智能化,智能大楼防雷系统设计在综合布线中的重要性...
  5. webApp调试页面的几种方式
  6. java实现远程桌面监控
  7. 计算机中计算平均数的函数是什么,Excel里怎么求平均数的?函数是什么?!excle2010怎么求平均数...
  8. mysql MERGE 错误(differently defined or of non-MyISAM type)
  9. 第一次去曼谷旅游怎么玩?这份省钱攻略请收好
  10. Gabor变换(1)
  11. UIAutomatorViewer初体验
  12. 四、LockSupport与线程中断
  13. 2022IC秋招面经分享【禾赛科技·FPGA开发工程师(上海)】
  14. 分号与逗号的区别及举例_顿号、逗号、分号的区别
  15. linux 访问西数网盘,西数不认盘,无法访问固件
  16. 红轴和茶轴哪个适合游戏 红轴和茶轴哪个手感好
  17. 基于V4L2的视频驱动开发(2
  18. Bootstarp未读消息铃铛
  19. 继电器学习笔记(一)——继电器的分类电磁继电器和磁保持继电器的工作原理
  20. C++友元函数实现两个复数相加

热门文章

  1. 何钦铭c语言第三版第9章答案,c语言程序设计第3版何钦铭 颜 晖 第9章 结构.pdf...
  2. 【无标题】 2022-2027年(新版)中国商业航天产业发展动态及投资战略研究报告
  3. 原创 关于微信拼车小程序开发的需求分析(分析建模)
  4. 钉钉企业邮箱smtp服务器
  5. (5/8 软件漏洞攻击利用技术)如何成为一名黑客(网络安全从业者)——网络攻击技术篇
  6. 音频D类功放LC滤波器设计(二)
  7. 恢复rm -rf 的数据
  8. 第一款个人应用——《不做手机控》——终于上线啦!
  9. EC2 Auto Scaling知识点
  10. EC20 centos7 调试_CentOS 7实现离线下载