Hello,
I am facing the same issue. I am using the freeSpire.pdf library version (7.8.9). I have to add one digital signature on multiple pages of the pdf file.
I have added a digital signature on each page of the pdf but when I open the pdf file it gives me an error like the attached screenshot.
Also, I have tried multiple ways but still, I am getting an error as "Signature Invalid, document altered". in this pdf, only the first signature gets a valid signature, and the remaining others get invalid.
Here is my code:-
Some parameters will get replaced by the original passed values
Public Function DigitallySignDocument()
Try
'Create a PdfDocument object and 'Load a sample PDF file
Dim doc As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument()
doc.LoadFromFile(PDFFilePath)
Dim PdfPageCount As Int16 = doc.Pages.Count
Dim DteTime As DateTime = DateTime.Now
While (PdfPageCount > 0)
'Load the certificate and Create a PdfSignature object and specify its position and size
Dim cert As Spire.Pdf.Security.PdfCertificate = New Spire.Pdf.Security.PdfCertificate(PfxFilePath, PswdForPfxFile)
PdfPageCount = PdfPageCount - 1
Dim signature As Spire.Pdf.Security.PdfSignature = New Spire.Pdf.Security.PdfSignature(doc, doc.Pages(PdfPageCount), cert, NameValue + Convert.ToString(PdfPageCount))
Dim rectangleF As RectangleF = New RectangleF(22, 40, 160, 44)
signature.Bounds = rectangleF
If PdfPageCount + 1 = doc.Pages.Count Then
signature.Certificated = False
End If
'Set the graphics mode to ImageAndSignDetail
signature.GraphicsMode = Spire.Pdf.Security.GraphicMode.SignImageAndSignDetail
signature.NameLabel = NameLabel
signature.Name = NameValue
signature.ContactInfoLabel = ContactInfoLabel
signature.ContactInfo = ContactInfoValue
signature.DateLabel = "Date"
signature.Date = DteTime
signature.LocationInfoLabel = LocationInfoLabel
signature.LocationInfo = LocationInfoValue
signature.ReasonLabel = ReasonLabel
signature.Reason = ReasonValue
signature.DistinguishedNameLabel = "DN:"
signature.DistinguishedName = signature.Certificate.IssuerName.Name
'Set the signature image source "D:\PDFWithDigitalSign2_0\check-mark-2.png"
signature.SignImageSource = Spire.Pdf.Graphics.PdfImage.FromFile(SignatureImagePath)
'Set the signature font
signature.SignDetailsFont = New Spire.Pdf.Graphics.PdfTrueTypeFont(New Font("Arial Unicode MS", 7.0F, FontStyle.Regular))
'Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = Spire.Pdf.Security.PdfCertificationFlags.ForbidChanges Or Spire.Pdf.Security.PdfCertificationFlags.AllowFormFill
End While
'Save to file
doc.SaveToFile(OutputFilePath)
doc.Close()
Return "Success"
Catch ex As Exception
Return ex.Message
End Try
End Function
What I have tried:
I tried changing the code.
As mentioned in the document
If PdfPageCount + 1 = doc.Pages.Count Then
signature.Certificated = False
End If