2012-03-22 58 views
3

我有一個由2人簽名的PDF(Eid)。如何使用ItextSharp檢索數字簽名信息(名稱,日期,...)

我試圖檢索這些信息,但目前爲止我還無法找到。

這是我到目前爲止有:

namespace ConsoleApplication1 
    { 
     class Program 
     { 
      static void Main(string[] args) 
      { 
       string workingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); 
       string inputFile = Path.Combine(workingFolder, "Tax Return.pdf");    

       PdfReader reader = new PdfReader(inputFile); 

       Console.ReadLine(); 
      } 
     } 
    } 

如果我在運行時檢查「讀者」我可以看到AcroForm有2場指向簽名,但我看不到任何具體信息關於這些簽名。

回答

7

短的例子:

StringBuilder sb = new StringBuilder(); 
PdfReader reader = new PdfReader(pdf); 
AcroFields af = reader.AcroFields; 
ArrayList names = af.GetSignatureNames(); 
for (int i = 0; i < names.Count; ++i) { 
    String name = (string)names[i]; 
    PdfPKCS7 pk = af.VerifySignature(name); 
    sb.AppendFormat("Signature field name: {0}\n", name); 
    sb.AppendFormat("Signature signer name: {0}\n", pk.SignName); 
    sb.AppendFormat("Signature date: {0}\n", pk.SignDate); 
    sb.AppendFormat("Signature country: {0}\n", 
    PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("C") 
); 
    sb.AppendFormat("Signature organization: {0}\n", 
    PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("O") 
); 
    sb.AppendFormat("Signature unit: {0}\n", 
    PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("OU") 
); 
} 
相關問題