We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DigitalSignature sample for multiple digital signatures is (no longer) working


The DigitalSignature sample for multiple digital signatures is (no longer) working.

My application has code that used to work (with, but now there is a problem when I try to add a second signature.

Attached you can find the pdf generated with your sample webapp called DigitalSignature. The signatures are not valid.

I upgraded the nuget packages to the latest version and the problem still persists.

I hope you can help.

Underneath is my original code that used to work:

Function Sign(signType As SignType, strPDFFile As String, img As Image, strCertificate As String) As Boolean

        If signType = SignType.None Then
            '* skip
            Return True


                Dim signatureImage As PdfBitmap = New PdfBitmap(img)

                Dim docStream As FileStream = New FileStream(strPDFFile, FileMode.Open, FileAccess.Read)
                Dim memstream As MemoryStream = New MemoryStream()
                Dim LoadedDocument As New PdfLoadedDocument(docStream)

                If IsNothing(LoadedDocument.Form) Then
                End If
                Dim intIndex As Integer = 0

                Dim matchRect As New Generic.Dictionary(Of Integer, Generic.List(Of Drawing.RectangleF))
                If LoadedDocument.FindText("{handtekening}", matchRect) Then
                    For Each kv As Generic.KeyValuePair(Of Integer, Generic.List(Of Drawing.RectangleF)) In matchRect

                        Dim loadedpage As PdfLoadedPage = LoadedDocument.Pages(kv.Key)
                        For Each r As Drawing.RectangleF In kv.Value
                            intIndex = intIndex + 1

                            'Dim i As New PdfImage()
                            'Dim loadedForm As PdfLoadedForm

                            If signType = SignType.eHealth Or signType = SignType.eID Then
                                Dim signatureField3 As New PdfSignatureField(loadedpage, "ncSignatureField" & intIndex)
                                'loadedForm = LoadedDocument.Form

                                signatureField3.Bounds = New RectangleF(r.X, r.Y - (signatureImage.Height / 2), signatureImage.Width / 2, signatureImage.Height / 2)
                                loadedpage.Graphics.DrawImage(signatureImage, r.X, r.Y, signatureImage.Width / 2, signatureImage.Height / 2)
                            End If

                End If


                If signType = SignType.eHealth Or signType = SignType.eID Then
                    Dim strKeystore As String
                    Dim strPWD As String
                    Dim pdfCert As PdfCertificate = Nothing

                    Select Case signType
                        Case SignType.eHealth


                            strKeystore = Solution.GetGlobalDefaultValue("KeystoreDir", "./eHealth/config/P12") & "/" & Solution.GetGlobalDefaultValue("PropertiesEnvironment", "prd") & "/" & Solution.SolutionVariables.EncryptionKeystore
                            strKeystore = Replace(strKeystore, "/", "\")
                            strPWD = Solution.SolutionVariables.EncryptionPassword

                            'Dim certificateStream1 As FileStream = New FileStream(strKeystore, FileMode.Open, FileAccess.Read)
                            'pdfCert = New PdfCertificate(certificateStream1, strPWD)
                            pdfCert = New PdfCertificate(strKeystore, strPWD)
                        Case SignType.eID
                            pdfCert = Syncfusion.Pdf.Security.PdfCertificate.FindBySerialId(Syncfusion.Pdf.Security.StoreType.MY, System.Convert.FromBase64String(strCertificate))
                    End Select

                    Dim signatureField As PdfLoadedSignatureField = Nothing
                    intIndex = 0

                        intIndex = intIndex + 1

                        LoadedDocument = New PdfLoadedDocument(memstream)

                        Dim page As PdfPageBase = LoadedDocument.Pages(0)

                        If LoadedDocument.Form.Fields.TryGetField("ncSignatureField" & intIndex, signatureField) Then

                            Dim signature As PdfSignature

                            signature = New PdfSignature(LoadedDocument, TryCast(signatureField.Page, PdfLoadedPage), pdfCert, "Signature", signatureField)
                            'signature.TimeStampServer = New TimeStampServer(New Uri("http://rfc3161timestamp.globalsign.com/advanced"))
                            'signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges
                            signature.ContactInfo = Solution.SolutionVariables.MedewerkerTelefoon
                            signature.LocationInfo = Solution.SolutionVariables.MedewerkerWoonplaats
                            signature.Reason = "I am author of this document."
                            signature.EnableLtv = False
                            'signature.Bounds = signatureField.Bounds

                            signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, signatureField.Bounds.Width, signatureField.Bounds.Height)
                            'signature.TimeStampServer = New TimeStampServer(New Uri("http://timestamp.entrust.net/TSS/RFC3161sha2TS"))

                            memstream = New MemoryStream()


                        End If

                        'memstream.Position = 0

                    Loop While Not IsNothing(signatureField)
                    LoadedDocument = New PdfLoadedDocument(memstream)
                End If


                Return True

            Catch ex As Exception
                Solution.ShowError(ex, "Fout in PDFSign.Sign")
                Return False
            End Try

        End If

    End Function

Attachment: DigitalSignatureSample_(1)_503945f3.zip

3 Replies

CM Chinnu Muniyappan Syncfusion Team November 8, 2019 04:39 AM

Hi Hugo Minoodt, 
Thank you for contacting Syncfusion support. 
On our analysis with the provided output document, we found that the signature failure is due to adding the trial version watermark to the signed PDF document (“Created with a trial version of Syncfusion Essential PDF”). The issue will be resolved once adding a proper license key while signing a PDF document. 
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to the below link to learn about generating and registering Syncfusion license key in your application to use the components without trail message. 
Kindly try the above and let us know whether the reported issue is resolved. 
Chinnu M 

HM Hugo Minoodt November 8, 2019 08:57 AM


With this info it worked for my sample app, but still not in my main app (same function!).

It seems that my app generates version 1.2 PDF files (which worked with) 16.x, but not with 17.x.

I had to add the line pdf.Version = Export.Pdf.Section.PdfVersion.Pdf17 and now it works.

Thanks for pointing me in the right way.



SL Sowmiya Loganathan Syncfusion Team November 11, 2019 12:51 AM

Hi Hugo, 

Thank you for the update. We glad to know that the issue was resolved. 

Sowmiya Loganathan 

Live Chat Icon For mobile
Up arrow icon