Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Feb 07, 2023 6:33 am

Hello,
I am facing the 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 all 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

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)

Dim rectangleF As RectangleF = New RectangleF(22, 40, 160, 44)
signature.Bounds = rectangleF

'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 = DateTime.Now

signature.LocationInfoLabel = LocationInfoLabel
signature.LocationInfo = LocationInfoValue

signature.ReasonLabel = ReasonLabel
signature.Reason = ReasonValue

signature.DistinguishedNameLabel = "DN:"
signature.DistinguishedName = signature.Certificate.IssuerName.Name

signature.Certificated = True
'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

fipldevops
 
Posts: 6
Joined: Thu Jan 19, 2023 1:52 pm

Tue Feb 07, 2023 6:52 am

Tue Feb 07, 2023 6:47 am

Hello,

Thanks for your inquiry.
Please kindly notice that the Free Spire.Pdf currently don’t support adding multiple digital signature to pdf file, however, our latest commercial version of Spire.PDF support this function, you can download the latest version (Spire.Pdf 9.2.2) and using the following code to test. Meanwhile, we are willing to provide a temporary license (one month free) to help you remove the warning message. If you need it, you can contact our sales team([email protected])

Code: Select all
 Sub Main()


        'Create a PdfDocument object and 'Load a sample PDF file
        Dim doc As Spire.Pdf.PdfDocument = New Spire.Pdf.PdfDocument()
        doc.LoadFromFile("../../data/testttt.pdf")

        Dim PdfPageCount As Int16 = doc.Pages.Count

        'Load the certificate and Create a PdfSignature object and specify its position and size
        Dim cert As X509Certificate2 = New X509Certificate2("../../data/gary.pfx", "e-iceblue")

        'Create PdfOrdinarySignatureMaker
        Dim signatureMaker As PdfOrdinarySignatureMaker = New PdfOrdinarySignatureMaker(doc, cert)


        While (PdfPageCount > 0)

            PdfPageCount = PdfPageCount - 1

            'Define the width of signature and height of signature, define the coordinate of signature
            Dim x As Single = 50
            Dim y As Single = 600
            Dim width As Single = 120
            Dim height As Single = 70
            Dim signName As String = PdfPageCount.ToString


            'Sign the Pdf
            PdfSign(doc, PdfPageCount, signatureMaker, cert, signName, x, y, width, height)

        End While

        'Save to file
        doc.SaveToFile("../../output/new_result_____.pdf")
        doc.Close()
    End Sub


    Private Sub PdfSign(ByVal doc As PdfDocument, ByVal PdfPageCount As Int16, ByVal signatureMaker As PdfOrdinarySignatureMaker, ByVal cert As X509Certificate2, ByVal signName As String, ByVal x As Single, ByVal y As Single, ByVal width As Single, ByVal height As Single)
        Try

            'Create appearance1
            Dim appearance1 As PdfSignatureAppearance = New PdfSignatureAppearance(signatureMaker.Signature)
            appearance1.NameLabel = "Signer"
            appearance1.ContactInfoLabel = "ContactInfo:"
            appearance1.LocationLabel = "Location:"
            appearance1.ReasonLabel = "Reason:"

            'Create signature1 And set details for the signature1
            Dim signature1 As PdfSignature = signatureMaker.Signature
            signature1.Name = signName
            signature1.ContactInfo = "Tom Tang"
            signature1.Location = "China"
            signature1.Reason = "protect document data"

            'Add signature1 to first page of PDF document.
            signatureMaker.MakeSignature(signName, doc.Pages(PdfPageCount), x, y, width, height, appearance1)
        Catch
        End Try
    End Sub


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Tue Feb 07, 2023 9:13 am

Hello Team,

Thanks for the reply.
But I have found the below details for "Free Edition". What you are informing me now is not mentioned in that page. Both the information is misleading on its own.

We are using the FreeSpire.Pdf version for testing purposes.
If it's successful then we will move ahead with the paid version.

**Free Edition $0
"The free version is limited to 10 pages of PDF. This limitation is enforced during the loading and creating files. When converting PDF to Image, the first 3 pages of PDF files will be converted to Image format successfully."

Link : https://www.e-iceblue.com/Introduce/fre ... -H2aHZBzDc

What can you suggest me to achive this?
How can I contact you regarding this?

fipldevops
 
Posts: 6
Joined: Thu Jan 19, 2023 1:52 pm

Tue Feb 07, 2023 10:08 am

Hello,

Thanks for your feedback.
The free version do support add single digital signature to Pdf file, however, the function of adding multiple digital signature to a pdf file is a new feature we recently added to the business Edition, and it hasn’t been synced to the free version yet.
In addition, there are the limitations you mentioned in free version, if your document exceeds the limitation, you can evaluate our commercial version(Spire.Pdf9.2.2). And We are willing to provide a temporary license (one month free) to help you remove the warning message and remove the function limitation. If you need it, you can contact our sales team([email protected]).

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.PDF