php 生成带有数字签名的 PDF

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/745779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:43:48  来源:igfitidea点击:

Generate PDF with digital signature

phppdf-generationdigital-signature

提问by lubosdz

Is it possible to generate PDF file in PHP with digital signature? An open-source solution is preferred.

是否可以使用数字签名在 PHP 中生成 PDF 文件?首选开源解决方案。

回答by lubosdz

TCPDF starting from version 5.5.001 (released 2010-06-23) can sign generated PDF documents.

TCPDF 从 5.5.001 版本(2010-06-23 发布)开始可以对生成的 PDF 文档进行签名。

It can also place transparent signature rectangle field over any bitmap/text, so clicking on the signature field brings up signature panel - cool feature. That same does seta-PDF signer, however you have to pay:-)

它还可以在任何位图/文本上放置透明的签名矩形字段,因此单击签名字段会显示签名面板 - 很酷的功能。seta-PDF 签名者也是如此,但是您必须付费:-)

If TCPDF extended with FPDI bridge, it can also parse already existing documents with PDF version up to 1.7 and sign it with X.509 certificate. It can 100% parse PDF documents generated by itself or pdf document craeted by any other PHP PDF tool (e.g. FPDF, DOM PDF, mPDF, ..), calculate PDF signature and write back the same signed PDF document.

如果TCPDF 扩展了FPDI 桥接器,它还可以解析已经存在的PDF 版本高达1.7 的文档,并使用X.509 证书对其进行签名。它可以 100% 解析自己生成的 PDF 文档或任何其他 PHP PDF 工具(例如 FPDF、DOM PDF、mPDF、..)生成的 PDF 文档,计算 PDF 签名并写回相同的签名 PDF 文档。

If, however, you want to parse PDF document created by other (e.g. binary) PDF generator (iText, ..), it may not be able to parse the document. You may try another PDF parser (I only know Zend Framework PDF Parser worth of trying), however it may not read and decompile whole structure of PDF document since PHP has limited implementation of PDF definitions (PHP is primary textual scripting language, cannot handle binary stuff easily, so this is the root of the limitation).

但是,如果您想解析由其他(例如二进制)PDF 生成器 (iText, ..) 创建的 PDF 文档,它可能无法解析该文档。您可以尝试另一个 PDF 解析器(我只知道 Zend Framework PDF Parser 值得一试),但是它可能无法读取和反编译 PDF 文档的整个结构,因为 PHP 对 PDF 定义的实现有限(PHP 是主要的文本脚本语言,无法处理二进制东西很容易,所以这是限制的根源)。

So if you are thinking about generating PDF on your web site, use the same tool for creating PDF document and signing - best I can recommend here is TCPDF. Look for it over google, if you haven't heard of it yet (:-o)

因此,如果您正在考虑在您的网站上生成 PDF,请使用相同的工具来创建 PDF 文档和签名 - 我在这里最好推荐的是 TCPDF。如果您还没有听说过,请通过 google 查找 (:-o)

At the time being, I dont think DOM PDF can sign PDF documents.

目前,我不认为 DOM PDF 可以签署 PDF 文档。

VersyPDF is .dll/.so PHP extension and is VERY BADLY supported, is expensive, and really POORLY documented. You may experience silent crashes without error messages... It also does not support 256-bit AES certificates, which are now standard. And you have to get different recompiled version if you are running on 32bit machines as developer and 64bit machines in production. We replaced VersyPDF with TCPDF. Performace penalty is hardly notable, we are able to generate dynamically 300 - 600 kB PDF signed documents. It's a pity, coz otherwise VersyPDF has somewhat nice API if you play with it and good performance. It's a one-man show I guess from my experience...

VersyPDF 是 .dll/.so PHP 扩展名,支持非常差,价格昂贵,而且文档记录很差。您可能会遇到没有错误消息的静默崩溃......它也不支持现在标准的 256 位 AES 证书。如果您在 32 位机器上作为开发人员和 64 位机器在生产中运行,您必须获得不同的重新编译版本。我们用 TCPDF 替换了 VersyPDF。性能损失几乎不显着,我们能够动态生成 300 - 600 kB 的 PDF 签名文档。很遗憾,否则 VersyPDF 有一些不错的 API,如果您使用它并且性能良好。根据我的经验,这是一场单人秀......

Cheers Lubos

干杯卢博斯

回答by Ginjo

The VersyPDF PHP library(Commercial) will also sign documents

VersyPDF PHP库(商业)也将签署文件

It is also possible to use the open source iTextjava library and a PHP-Java bridgeto allow communication. See the iText FAQon this

还可以使用开源iTextjava 库和PHP-Java 桥来进行通信。见iText的常见问题解答这个

iText can sign documents by self signing, veriSign plug-in or windows Certificate Security. When I've used it in the past on Java projects, signing documents is just coping examplesand usually takes under a hundred lines. The hardest bit is getting the right certificates to sign it with.

iText 可以通过自签名、veriSign 插件或 windows Certificate Security 对文档进行签名。当我过去在 Java 项目中使用它时,签署文档只是应对示例,通常需要不到一百行。最难的是获得正确的证书来签名。

回答by ólafur Waage

There's something called SetaPDF-Signer.It's not free though :S

有一种叫做 SetaPDF-Signer 的东西。虽然它不是免费的:S

The SetaPDF-Signer API allows PHP developers to digital sign PDF documents in pure PHP.

SetaPDF-Signer API 允许 PHP 开发人员在纯 PHP 中对 PDF 文档进行数字签名。