iTextSharp 給現有的PDF插一個空章

寫這個方法,也是搞了比較久的,因為資料比較少.

開始,用 Adobe LiveCycle Designer 也是可以往 PDF裡面插入空章的.但是,空章的FieldID 很長一串,比如設置ID 為 A,則顯示

"topmostSUbform[0].Page1[0].A[0]",簽核的時候無法定位.用iTextSharp 的 PDFStamper往現有的PDF裡面插,就沒有這個問題!

但是,如何把 Reader的流到 PDFWriter裡面去,確實找了很久.

       public void AddEmptySignature(string strLocalFile,string outputFile)
        {
            PdfReader reader = new PdfReader(strLocalFile);
            FileStream sio = new FileStream(outputFile, FileMode.Create);
            PdfStamper stamp = new PdfStamper(reader, sio, '\0', true);
            PdfWriter writer = stamp.Writer;
            PdfFormField field = PdfFormField.CreateSignature(writer);
            field.SetFieldFlags(0);
            PdfBorderDictionary border = new PdfBorderDictionary(0, 0);
            field.BorderStyle = border;
            PdfAcroForm paf = writer.AcroForm;
            paf.SetSignatureParams(field, "SignatureID", 30, 50, 235, 200);
            stamp.AddAnnotation(field, 1);
            stamp.FormFlattening = false;
            stamp.Close();
            //writer.Close();
            //reader.Close();
        }

 

 

 

你可能感兴趣的:(iTextSharp 給現有的PDF插一個空章)