Programming in C#.NET. When setting all form fields except the signature field to readonly of an editable PDF file, the signature field will become invalid. The signature field will not be changed.
The signature is a PKCS#12 pfx file, that is used to set the signature manually into the signature field.
Any help would be appreciated.
Aspose.Pdf version 20.9.0.0
.NET Framework 4.7.2
I discovered that saving the file seems to break the signature field?
Is it possible to change the document without invalidating the signature by specifying the changes?
Code to set form fields readonly:
var pdfDoc = new Document(fileName);
foreach (var field in pdfDoc.Form.Fields)
{
if (field.PartialName != "DigitalSignature")
{
//field.Flatten();
field.ReadOnly = true;
}
}
pdfDoc.Save(fileName);
I tried also this code instead of above code (still signature is invalid):
DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;
//privilege.ChangeAllowLevel = 1;
privilege.AllowPrint = true;
//privilege.AllowCopy = true;
// Create PdfFileSecurity object
PdfFileSecurity fileSecurity = new PdfFileSecurity();
fileSecurity.BindPdf(fileName);
var tempPath = FileHelper.GetTempFileName("pdf");
// Set document privileges
fileSecurity.SetPrivilege(privilege);
fileSecurity.Save(tempPath);
FileHelper.Delete(fileName);
return tempPath;