我想在我的动态 pdf 中使用 itext sharp 和签名插入 acrofield 添加数字签名
I want add digital signature in my dynamic pdf with using itext sharp and in signature insert acrofield
我试图使用 itextsharp 在数字签名中插入文本字段,但无法在电子签名中插入该文本。
我的代码请检查另外我想验证签名仍然不能执行此代码任何建议都是合适的..
public void Sign(string SigReason, string SigContact, string SigLocation, bool visible)
{
string password = @"123";
PdfReader reader = new PdfReader(this.inputPDF,new System.Text.ASCIIEncoding().GetBytes(password));
//Activate MultiSignatures
PdfStamper st = PdfStamper.CreateSignature(reader, new FileStream(this.outputPDF, FileMode.Create, FileAccess.Write), '[=10=]', null, true);
//To disable Multi signatures uncomment this line : every new signature will invalidate older ones !
//PdfStamper st = PdfStamper.CreateSignature(reader, new FileStream(this.outputPDF, FileMode.Create, FileAccess.Write), '[=10=]');
//string pdfTemplate = Server.MapPath("~/Data/PADForm.pdf");
//string newFile = Server.MapPath("~/Data/newFile.pdf");
//signPdfFile(sourceDocument, destinationPath, stream, "123", "testing", "testing");
//PdfReader pdfReader = new PdfReader(pdfTemplate, new System.Text.ASCIIEncoding().GetBytes(password));
//PdfStamper pdfStamper = new PdfStamper(reader, new FileStream(this.outputPDF, FileMode.Create));
string imageURL = @"C:\Users\amitrs\Desktop\FSI SS4-25.png";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
// Resize image depend upon your need
jpg.ScaleToFit(140f, 120f);
//Give space before image
jpg.SpacingBefore = 10f;
//Give some space after the image
jpg.SpacingAfter = 1f;
jpg.Alignment = Element.ALIGN_LEFT;
AcroFields pdfFormFields = st.AcroFields;
pdfFormFields.SetField("DigitalSignature", "Amit");
pdfFormFields.SetField("Signature", "Amit Saini");
st.MoreInfo = this.metadata.getMetaData();
st.XmpMetadata = this.metadata.getStreamedMetaData();
PdfSignatureAppearance sap = st.SignatureAppearance;
sap.SetCrypto(this.myCert.Akp, this.myCert.Chain, null, PdfSignatureAppearance.VERISIGN_SIGNED);
sap.Reason = SigReason;
sap.Contact = SigContact;
sap.Location = SigLocation;
if (visible)
sap.SetVisibleSignature(new iTextSharp.text.Rectangle(100, 100, 250, 300), 1, null);
st.Close();
}
iTextSharp 签名外观对象有 2 个 属性,您必须设置 属性。
PdfSignatureAppearance sap = st.SignatureAppearance;
sap.Layer2Text = "XYZ";
希望对您有所帮助
我试图使用 itextsharp 在数字签名中插入文本字段,但无法在电子签名中插入该文本。
我的代码请检查另外我想验证签名仍然不能执行此代码任何建议都是合适的..
public void Sign(string SigReason, string SigContact, string SigLocation, bool visible)
{
string password = @"123";
PdfReader reader = new PdfReader(this.inputPDF,new System.Text.ASCIIEncoding().GetBytes(password));
//Activate MultiSignatures
PdfStamper st = PdfStamper.CreateSignature(reader, new FileStream(this.outputPDF, FileMode.Create, FileAccess.Write), '[=10=]', null, true);
//To disable Multi signatures uncomment this line : every new signature will invalidate older ones !
//PdfStamper st = PdfStamper.CreateSignature(reader, new FileStream(this.outputPDF, FileMode.Create, FileAccess.Write), '[=10=]');
//string pdfTemplate = Server.MapPath("~/Data/PADForm.pdf");
//string newFile = Server.MapPath("~/Data/newFile.pdf");
//signPdfFile(sourceDocument, destinationPath, stream, "123", "testing", "testing");
//PdfReader pdfReader = new PdfReader(pdfTemplate, new System.Text.ASCIIEncoding().GetBytes(password));
//PdfStamper pdfStamper = new PdfStamper(reader, new FileStream(this.outputPDF, FileMode.Create));
string imageURL = @"C:\Users\amitrs\Desktop\FSI SS4-25.png";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
// Resize image depend upon your need
jpg.ScaleToFit(140f, 120f);
//Give space before image
jpg.SpacingBefore = 10f;
//Give some space after the image
jpg.SpacingAfter = 1f;
jpg.Alignment = Element.ALIGN_LEFT;
AcroFields pdfFormFields = st.AcroFields;
pdfFormFields.SetField("DigitalSignature", "Amit");
pdfFormFields.SetField("Signature", "Amit Saini");
st.MoreInfo = this.metadata.getMetaData();
st.XmpMetadata = this.metadata.getStreamedMetaData();
PdfSignatureAppearance sap = st.SignatureAppearance;
sap.SetCrypto(this.myCert.Akp, this.myCert.Chain, null, PdfSignatureAppearance.VERISIGN_SIGNED);
sap.Reason = SigReason;
sap.Contact = SigContact;
sap.Location = SigLocation;
if (visible)
sap.SetVisibleSignature(new iTextSharp.text.Rectangle(100, 100, 250, 300), 1, null);
st.Close();
}
iTextSharp 签名外观对象有 2 个 属性,您必须设置 属性。
PdfSignatureAppearance sap = st.SignatureAppearance;
sap.Layer2Text = "XYZ";
希望对您有所帮助