Click here to Skip to main content
15,905,504 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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()
           'Create a PdfDocument object and 'Load a sample PDF file
           Dim doc As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument()

           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

           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
Updated 6-Feb-23 22:09pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900