2011-12-17 64 views
3

我正在使用winforms在使用itextsharp的PDF表單中添加簽名字段 以下是我嘗試的代碼。在C#中使用iTextSharp添加簽名字段

EDITED

var writer = new PdfWriter(outputPdfStream); 
PdfFormField SigField = PdfFormField.CreateSignature(writer); 

運行第二線時拋出以下錯誤:

Error 1 'iTextSharp.text.pdf.PdfWriter' does not contain a constructor that takes 1 arguments 

我還在學習iTextSharp的插件和出來的。任何指導非常感謝。

謝謝!

+0

「下面是我在想嘗試代碼」 - 你的意思是,你還沒有真正嘗試過嗎?也許先嚐試一下,然後回來,可能會遇到任何問題。 – 2011-12-18 00:01:21

+0

我試過了。我對此感到抱歉。我更新了這個問題。 – Beak 2011-12-18 00:05:14

回答

3

錯誤是告訴你,沒有一個構造函數iTextSharp.text.pdf.PdfWriter需要一個參數。

How to sign a PDF using iText and iTextSharp

KeyStore ks = KeyStore.getInstance("pkcs12"); 
ks.load(new FileInputStream("my_private_key.pfx"), "my_password".toCharArray()); 
String alias = (String)ks.aliases().nextElement(); 
PrivateKey key = (PrivateKey)ks.getKey(alias, "my_password".toCharArray()); 
Certificate[] chain = ks.getCertificateChain(alias); 
PdfReader reader = new PdfReader("original.pdf"); 

FileOutputStream fout = new FileOutputStream("signed.pdf"); 
PdfStamper stp = PdfStamper.createSignature(reader, fout, '\0'); 

PdfSignatureAppearance sap = stp.getSignatureAppearance(); 
sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED); 
sap.setReason("I'm the author"); 
sap.setLocation("Lisbon"); 
// comment next line to have an invisible signature 
sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null); 
stp.close(); 
相關問題