Adding a digital signature to a pdf file

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?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Use a PDF editing library. I’ve used this one before:

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

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x