when I sign a document the signature only appears on the first page. Is there anything I can do to make it appear on every page? This is the method I'm using right now to sign the PDF, hope it helps find a solution:
public static PdfStamper SignHashedUser(string Target, SysX509.X509Certificate2 Certificate, string Reason, string Location, bool AddVisibleSign, PdfReader objReader, int pags)
{
X509CertificateParser objCP = new X509CertificateParser();
X509Certificate[] objChain = new X509Certificate[] { objCP.ReadCertificate(Certificate.RawData) };
PdfStamper objStamper = PdfStamper.CreateSignature(objReader, new FileStream(Target, FileMode.Create), '');
PdfSignatureAppearance objSA = objStamper.SignatureAppearance;
int[] perms = { PdfWriter.AllowPrinting, PdfWriter.AllowFillIn };
if (AddVisibleSign)
objSA.SetVisibleSignature(new Rectangle(50, 50, 250, 100), pags, null);
//pags define in which page of the PDF will the signature appear
objSA.SignDate = DateTime.Now;
objSA.SetCrypto(null, objChain, null, null);
objSA.Acro6Layers = true;
objSA.Render = PdfSignatureAppearance.SignatureRender.NameAndDescription;
PdfSignature objSignature = new PdfSignature(PdfName.ADOBE_PPKMS, PdfName.ADBE_PKCS7_SHA1);
objSignature.Date = new PdfDate(objSA.SignDate);
objSignature.Name = PdfPKCS7.GetSubjectFields(objChain[0]).GetField("CN");
if (objSA.Reason != null)
objSignature.Reason = objSA.Reason;
if (objSA.Location != null)
objSignature.Location = objSA.Location;
objSA.CryptoDictionary = objSignature;
int intCSize = 4000;
Hashtable objTable = new Hashtable();
objTable[PdfName.CONTENTS] = intCSize * 2 + 2;
objSA.PreClose(objTable);
HashAlgorithm objSHA1 = new SHA1CryptoServiceProvider();
Stream objStream = objSA.RangeStream;
int intRead = 0;
byte[] bytBuffer = new byte[8192];
while ((intRead = objStream.Read(bytBuffer, 0, 8192)) > 0)
objSHA1.TransformBlock(bytBuffer, 0, intRead, bytBuffer, 0);
objSHA1.TransformFinalBlock(bytBuffer, 0, 0);
byte[] bytPK = SignMsg(objSHA1.Hash, Certificate, false);
byte[] bytOut = new byte[intCSize];
PdfDictionary objDict = new PdfDictionary();
Array.Copy(bytPK, 0, bytOut, 0, bytPK.Length);
objDict.Put(PdfName.CONTENTS, new PdfString(bytOut).SetHexWriting(true));
objSA.Close(objDict);
return objStamper;
}
EDIT: PdfSignatureAppearance.SetVisibleSignature() is a method including a parameter indicating the page where the Signature should be displayed. However it can't be used to determine the number of pages where one's signature would be shown..
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…