Adding a digital signature to a pdf file [duplicate]

梦想与她 提交于 2019-11-28 09:22:41

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

JoeManiaci

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!