PdfLoadedSignatureField field = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
//Loads the PDF document with signature field
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
//Gets the page
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
PdfCertificate certificate = new PdfCertificate(@"PDF.pfx", "syncfusion");
//Creates a signature field
PdfSignatureField signatureField = new PdfSignatureField(page, "Signaturefield");
signatureField.Bounds = new RectangleF(100, 100, 100, 100);
var signature = new PdfSignature(loadedDocument, page, certificate, "Signature");
signatureField.Signature = signature;
//Adds certificate to the signature field
signatureField.Signature.Certificate = certificate;
signatureField.BackColor = Color.Black;
signatureField.BorderWidth = 5;
//Adds the field
loadedDocument.Form.Fields.Add(signatureField);
|
Thanks Sowmiya. I have integrated your code. It does not throw errors, but Adobe does not indicate there is a signature, though Foxit does. Furthermore, Foxit shows there are two identical signatures. Here is my modified code:
public static Stream DigitallyCertifyPdfStream(Stream uncertifiedFileStream, CertificationBundle certificationBundle)
{
var loadedDocument = new PdfLoadedDocument(uncertifiedFileStream);
var page = loadedDocument.Pages[0] as PdfLoadedPage;
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{Guid.NewGuid()}.pfx");
File.WriteAllBytes(filePath, certificationBundle.ToBytes());
var certificate = new PdfCertificate(filePath, certificationBundle.Password);
// Signature
var signature = new PdfSignature(loadedDocument, page, certificate, "Signature");
var signatureField = new PdfSignatureField(page, "Signaturefield");
signatureField.Bounds = new RectangleF(100, 100, 100, 100);
signatureField.Signature = signature;
signatureField.Signature.Certificate = certificate;
signatureField.BackColor = Color.Black;
signatureField.Visible = false;
loadedDocument.Form.Fields.Add(signatureField);
// Encrypted, password protected PDF
loadedDocument.Security.KeySize = PdfEncryptionKeySize.Key256Bit;
loadedDocument.Security.Algorithm = PdfEncryptionAlgorithm.AES;
loadedDocument.Security.OwnerPassword = certificationBundle.Password;
loadedDocument.Security.Permissions = PdfPermissionsFlags.EditAnnotations | PdfPermissionsFlags.Print;
var digitallySignedPdf = new MemoryStream();
loadedDocument.Save(digitallySignedPdf);
loadedDocument.Close(true);
return digitallySignedPdf;
}
I have also examined the generated PDF file (attached) and found /Type /Sig entries. Why are these not being picked up on in Adobe Reader?
Thanks, I have changed my code so that there is just one signature, but it is still not being recognized/listed by Adobe Reader. I do see the signature in Foxit Reader.
Here is a screenshot of Foxit showing the signature:
And here is a screenshot of the same PDF in Adobe Reader where it does not recognize the signature
I am not concerned about a visible signature on the page itself, just that the PDF readers recognize that it has been digitally signed.
Thanks for your help.
Hey, thanks for looking into this. I see that the document you have provided does work, but I am still experiencing problems.
I posted a question on StackOverflow. I wonder if the answer may shed any light to you on what is happening.
https://stackoverflow.com/questions/45451470/pdf-shows-signature-in-foxit-reader-but-not-adobe-reader
Thanks for continuing to look into this.Scott H
Sowmiya, thank you for making a sample project. I ran your project and it did indeed work. However when I switched out Data/Input.pdf with this PDF (the one that is referenced in my StackOverflow question) it did not work. Any idea why?
Thanks for all your work in investigating.
Hi, Sowmiya, thanks for continuing to look into it. I am not using Essential Studio, but am using the Nuget package, whose version is 14.1.0.46. It was last published over a year ago (see Nuget). Does its version number correspond with the Essential Studio version number? Should a publish be done of the Nuget package?
We prefer to use Visual Studio with the Nuget packages. If I downloaded Essential Studio, would I be able to copy the DLLs over and use those?
Thanks! It works for me now that I am pointed to Syncfusion Nuget servers. You really should update your packages on nuget.org.
Scott Hoelsema