Hello,
Thanks for your inquiry.
Kindly note that to sign a document multiple times, you need to save the pdf after a signature, and then load the pdf and sign the document again, as shown below.
- Code: Select all
String input = @"input.pdf";
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(input);
//Load the certificate
String pfxPath = @"xxx.pfx";
PdfCertificate cert = new PdfCertificate(pfxPath, "e-iceblue");
PdfSignature signature = new PdfSignature(doc, doc.Pages[0], cert, "signature0");
signature.Bounds = new RectangleF(new PointF(90, 100), new SizeF(270, 90));
//Load sign image source.
signature.SignImageSource = PdfImage.FromFile(@"Logo.png");
//Set the dispay mode of graphics, if not set any, the default one will be applied
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
signature.NameLabel = "Signer:";
signature.Name = "Gary";
signature.ContactInfoLabel = "ContactInfo:";
signature.ContactInfo = signature.Certificate.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, true);
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "Chengdu";
signature.ReasonLabel = "Reason: ";
signature.Reason = "The certificate of this document";
signature.DistinguishedNameLabel = "DN: ";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
//signature.Certificated = true;
//Set fonts. if not set, default ones will be applied.
signature.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15);
//Set the sign image layout mode
signature.SignImageLayout = SignImageLayout.None;
//save the pdf and then load it and sign again
MemoryStream ms = new MemoryStream();
doc.SaveToStream(ms);
doc.LoadFromStream(ms);
signature = new PdfSignature(doc, doc.Pages[0], cert, "signature1");
signature.Bounds = new RectangleF(new PointF(90, 300), new SizeF(270, 90));
//Load sign image source.
signature.SignImageSource = PdfImage.FromFile(@"Logo.png");
//Set the dispay mode of graphics, if not set any, the default one will be applied
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
signature.NameLabel = "Signer:";
signature.Name = "Gary";
signature.ContactInfoLabel = "ContactInfo:";
signature.ContactInfo = signature.Certificate.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, true);
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "Chengdu";
signature.ReasonLabel = "Reason: ";
signature.Reason = "The certificate of this document";
signature.DistinguishedNameLabel = "DN: ";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
//signature.Certificated = true;
//Set fonts. if not set, default ones will be applied.
signature.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15);
//Set the sign image layout mode
signature.SignImageLayout = SignImageLayout.None;
doc.SaveToFile(@"DigitalSignature.pdf");
doc.Close();
Also, if you are using our commercial version, you need to apply a valid license in your application, otherwise it will add warning message to the PDF, which changes the content of the document and will cause the signature to become invalid. We are willing to provide a temporary license (one month free) to help you remove the warning message. You can contact our sales team (
sales@e-iceblue.com) to get it.
If there are any questions, please feel free to write back.
Sincerely,
Rachel
E-iceblue support team