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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Cannot sign PDF with LTV enabled

Thread ID:





140722 Nov 3,2018 06:50 PM UTC Nov 9,2018 09:54 AM UTC WinForms 3
Tags: PDF
Asked On November 3, 2018 06:50 PM UTC


I am trying to sign a pdf using LTV but I get a NullReferenceException.

I followed the guide on the controls' documentation.
I successfully created a PDF without LTV. The following code works fine if is set signature.EnableLtv = false .

Private Function CreatePdf(myCert As X509Certificate2 ) As String
            dim cert as PdfCertificate = new PdfCertificate(myCert)
            Dim doc As New PdfDocument()
            Dim page As PdfPageBase = doc.Pages.Add()
            Dim graphics As PdfGraphics = page.Graphics
            Dim signature As New PdfSignature(doc, page, cert, "Signature")
            signature.TimeStampServer = New TimeStampServer(New Uri("http://timestamp.ermis.gov.gr/TSS/HttpTspServer"))
            signature.Bounds = New RectangleF(New PointF(100, 200), new SizeF(100,100))
            signature.ContactInfo = "CONTACT"
            signature.LocationInfo = "LOCATION"
            signature.Reason = "REASON"
            signature.Bounds = New RectangleF(New PointF(100, 100), New SizeF(50, 50))
            Dim _font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 14)
            graphics.DrawString("Hello world!", _Font, PdfBrushes.Black, New PointF(0, 0))
            signature.EnableValidationAppearance = True

            signature.EnableLtv = true

            Return "OK"
        Catch ex As Exception
            Return ex.Message.ToString()
        End Try
    End Function

When I set  "signature.EnableLtv=True" I get the following error:

{"Object reference not set to an instance of an object."}
   at Syncfusion.Pdf.Security.PdfSignature.set_EnableLtv(Boolean value)
   at Tests.Form1.CreatePdf(X509Certificate2 myCert) in ... Form1.vb:line 105

The lin 105 is the exact line where I assign the value to EnableLtv: signature.EnableLtv=True

Do you have any suggestions?

KarthikeyanC [Syncfusion]
Replied On November 5, 2018 05:12 PM UTC

Hi Stavros, 
LTV for signature will only works when load the certificate (.pfx) from a file or stream using PdfCertificate instance and it does not support if the certificate is loaded from X509Certificate2 API like you have used in your previous code snippet.  

So kindly use the code snippet mentioned below to enable LTV in the signature of PDF document:  
'Load the certificate from a path or as a stream  
Dim cert As PdfCertificate = New PdfCertificate("C://temp//pdf.pfx", "syncfusion")  
Dim doc As PdfDocument = New PdfDocument  
Dim page As PdfPageBase = doc.Pages.Add  
Dim graphics As PdfGraphics = page.Graphics  
Dim signature As PdfSignature = New PdfSignature(doc, page, cert, "Signature")  
signature.TimeStampServer = New TimeStampServer(New Uri("http://timestamp.ermis.gov.gr/TSS/HttpTspServer"))  
signature.Bounds = New RectangleF(New PointF(100, 200), New SizeF(100, 100))  
signature.ContactInfo = "CONTACT"  
signature.LocationInfo = "LOCATION"  
signature.Reason = "REASON"  
signature.Bounds = New RectangleF(New PointF(100, 100), New SizeF(50, 50))  
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 14)  
graphics.DrawString("Hello world!", font, PdfBrushes.Black, New PointF(0, 0))  
signature.EnableValidationAppearance = True  
signature.EnableLtv = True  


Replied On November 8, 2018 12:53 PM UTC

I use a certificate stored on a HSM with non-exportable private key.

Thanks for the info, anyway. I'll try to find a workaround.

KarthikeyanC [Syncfusion]
Replied On November 9, 2018 09:54 AM UTC

Hi Stavros,
Thanks for your update, we will fix the mentioned null reference exception while enabling LTV in the upcoming volume 4 release.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon