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), '\0');
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..
Actually you may have one signature field and one corresponding widget annotation and also put images or other objects representing this signature in all other places.
Allow me to copy a sentence and a note from ISO-32000-2. This document isn't available yet because it will only be released in 2016. However, it is very clear on the subject of this question:
This has always been true, however: it was only documented in documentation proprietary to Adobe. Starting with PDF 2.0, it will be normative.
In short: you are asking for something that is in violation with the PDF specification.