PDF数字签名:外观中签署日期的更改日期格式

时间:2016-10-01 06:44:38

标签: c# itext digital-signature

我已成功使用iTexhSharp.dll(5.5.9)实现数字PDF签名,但我想更改签名日期的日期格式,该日期格式目前显示在'2016/10/01 00:00:00 +05 '30''这种格式,想要改变DD / MM / YYYY HH:MM:SS。请帮助我。

我的代码:

PdfSignatureAppearance appearance = stamper.SignatureAppearance;
 //appearance.Reason = SignReason;
 //appearance.Location = SignLocation;
 appearance.SignDate = DateTime.Now.Date;
 appearance.SetVisibleSignature(new iTextSharp.text.Rectangle(xPos, yPos, xPos + 200, yPos + 100), PageNo, "Signature1");//.IsInvisible

// Custom text and background image
appearance.Image = iTextSharp.text.Image.GetInstance(SignatureImg);
appearance.ImageScale = 0.6f;
appearance.Image.Alignment = 300;
appearance.Acro6Layers = true;

//digital signature
IExternalSignature es = new PrivateKeySignature(pk, "SHA-256");
MakeSignature.SignDetached(appearance, es, new Org.BouncyCastle.X509.X509Certificate[] { pk12.GetCertificate(alias).Certificate }, null, null, null, 0, CryptoStandard.CMS);

    stamper.Close();

1 个答案:

答案 0 :(得分:1)

您可以使用PdfSignatureAppearance属性Layer2Text设置签名可视化中使用的文字:

appearance.Layer2Text = "...";

默认情况下,iTextSharp会像这样创建此文本

StringBuilder buf = new StringBuilder();
buf.Append("Digitally signed by ");
String name = null;
CertificateInfo.X509Name x500name = CertificateInfo.GetSubjectFields((X509Certificate)signCertificate);
if (x500name != null) {
    name = x500name.GetField("CN");
    if (name == null)
        name = x500name.GetField("E");
}
if (name == null)
    name = "";
buf.Append(name).Append('\n');
buf.Append("Date: ").Append(signDate.ToString("yyyy.MM.dd HH:mm:ss zzz"));
if (reason != null)
    buf.Append('\n').Append(reasonCaption).Append(reason);
if (location != null)
    buf.Append('\n').Append(locationCaption).Append(location);
text = buf.ToString(); 
PdfSignatureAppearance.GetAppearance()中的

。您可以将此作为Layer2Text创建代码的模板。 (显然,您必须适当地替换对PdfSignatureAppearance成员的访问权限。)特别是您可以看到日期格式字符串,并可以相应地更改它。