錯誤是告訴你,沒有一個構造函數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();
「下面是我在想嘗試代碼」 - 你的意思是,你還沒有真正嘗試過嗎?也許先嚐試一下,然後回來,可能會遇到任何問題。 – 2011-12-18 00:01:21
我試過了。我對此感到抱歉。我更新了這個問題。 – Beak 2011-12-18 00:05:14