Adding a digital signature to a pdf file [duplicat

2019-01-18 07:00发布

问题:

Possible Duplicate:
Digitally sign PDF files

In the application a user will upload a PDF file and then upload a personal signature created using a digital pen. How can I embed this signature in the pdf file?

回答1:

Use a PDF editing library. I've used this one before: http://pdfsharp.com/PDFsharp/



回答2:

As far as I have been able to figure out, you can't programmatically sign the document and still have it be a valid signature. I am looking at this from the most strictest of positions though. I am a DoD contractor tasked with doing as much as I can automating the creating of pdf documents and then the signing of them with our smartcards which contain public keys for official digital signatures.

As far as I could tell, there was no way of gaining access to the Windows Certificate Store and grabbing my public key in a useable form. You can export your signature through adobe acrobat pro(don't have standard now) but it wouldn't be anything usable.

So my final solution was to build two documents. One was programmatically in PDFSharp and would become the final document. The other was a blank document built in Adobe Acrobat Pro that only contained the two signature fields necessary for the final document. In case anyone tries this, you also have to optimize the file in V. 5.0 of the .pdf format.

Although PDFSharp can not handle signature fields currently, it will however leave them alone. So I opened the original(blank w/ signatures) in edit mode, so instead of...

PdfDocument document = new PdfDocument("Name");

I used...

PdfDocument document = PdfReader.Open("Name");

and instead of creating the first page for the final document, I just reused the blank page and added everything else to it using...

PdfPage page = document.Pages[0];

As far as I can tell this is the only workaround there is besides every other post I have found recommending iText. After PDFSharp, I could not stand working in iText(Sharp technically).

You also have to make sure you save your document object as a different name since it will technically be opened.