Generate PDF with digital signature

onidlo picture onidlo · Apr 14, 2009 · Viewed 24.4k times · Source

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

Answer

lubosdz picture lubosdz · Sep 6, 2010

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

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:-)

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.

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).

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)

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

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...

Cheers Lubos