我籤使用5.5版本的iTextSharp的的PDF文檔。 以下是示例代碼。
// Set the reader (PdfReader) and output (Stream) first
PdfStamper stamper = PdfStamper.CreateSignature(reader, output, '\0');
PdfSignatureAppearance signatureAppearance = stamper.SignatureAppearance;
signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION;
signatureAppearance.Reason = "I love signing";
signatureAppearance.LocationCaption = "";
signatureAppearance.SignatureGraphic = Image.GetInstance(this.imageFolderPath + "sign.png");
signatureAppearance.SetVisibleSignature(
new Rectangle(100, 100, 300, 200),
reader.NumberOfPages,
"Signature");
// Get certificate from store, here I am reading file
X509Certificate2 cert = new X509Certificate2(certFile, certPassword);
var keyPair = DotNetUtils.GetKeyPair(cert.PrivateKey).Private;
BcX509.X509Certificate bcCert = DotNetUtils.FromX509Certificate(cert);
var chain = new List<BcX509.X509Certificate> { bcCert };
IExternalSignature signature = new PrivateKeySignature(keyPair, "SHA-256");
MakeSignature.SignDetached(signatureAppearance, signature, chain, null, null, null, 0, CryptoStandard.CMS);
stamper.Close();
簽名API(至少是您期望使用的最高級別)已經發生了一些變化。您可能需要閱讀[PDF文檔的數字簽名](http://itextpdf.com/book/digitalsignatures),*由Bruno Lowagie(iText Software)*編寫的白皮書*與iText(Sharp)簽署。其中的代碼示例使用Java,但C#版本也可用。 – mkl
你可以給我提供C#鏈接嗎? –
它們至少可以在[tutorial](http://svn.code.sf.net/p/itextsharp/code/tutorial)中的subversion版本庫中找到;不過,我不知道是否有任何美化版本。 – mkl