当我使用 ITextSharp 对已使用此代码进行数字签名的文档进行数字签名时,它会使其他签名无效。如果我使用文本或图像进行数字签名,它可以正常工作。这是 Adobe/Itextsharp 限制还是代码有问题?
public void SignWithLine(string pdfFilePath, string outputFilePath, LineAnnotation lineAnnotation)
{
double xStartPoint = 89.285969238281268, yStartPoint = 343.08978515624881, xEndPoint = 72.7515234375, yEndPoint = 496.03341796874878, lineStroke = .24;
CertificateWrapper certificate = CertificateWrapper.GetCertificateInformationFromSignature(GetCertificateInformation());
PdfReader reader = new PdfReader(pdfFilePath);
PdfTemplate layer = null;
using (PdfStamper signature = PdfStamper.CreateSignature(reader, null, '\0', outputFilePath, true))
{
PdfSignatureAppearance signatureAppearance = signature.SignatureAppearance;
signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.GRAPHIC;
Rectangle rect = new Rectangle((float)Math.Min(xStartPoint, xEndPoint), (float)Math.Min(yStartPoint, yEndPoint), (float)Math.Min(xStartPoint, xEndPoint) + (float)Math.Abs(xEndPoint - xStartPoint), (float)Math.Min(yStartPoint, yEndPoint) + (float)Math.Abs(yEndPoint - yStartPoint));
signatureAppearance.SetVisibleSignature(rect, lineAnnotation.PageIndex + 1, GetCertificateFieldName());
layer = signatureAppearance.GetLayer(2);
PdfContentByte cb = signature.GetUnderContent(lineAnnotation.PageIndex + 1);
cb.SetLineWidth((float)lineStroke);
cb.MoveTo((float)xStartPoint, (float)yStartPoint);
cb.LineTo((float)(xEndPoint), (float)(yEndPoint));
cb.Stroke();
signatureAppearance.CertificationLevel = PdfSignatureAppearance.NOT_CERTIFIED;
// Normal signature, not a certification
MakeSignature.SignDetached(signatureAppearance, certificate.DigitalSignature, certificate.Chain, null, null, null, 0, true);
signature.Close();
}
}