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: June 24, 2019).
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 Oct 24,2019 03:52 PM UTC WinForms 5
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?

Karthikeyan Chandrasekar [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.

Karthikeyan Chandrasekar [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.


Thorsten Twellmann
Replied On August 7, 2019 06:22 PM UTC

Does Syncfusion plan to support LTV in combination with certificates on HSM, e.g. USB tokens, in the near future?

Thanks Thorsten

Surya Kumar [Syncfusion]
Replied On August 8, 2019 02:11 PM UTC

Hi Thorsten, 

We can create LTV enabled signature PDF by loading certificate as X509Certificate2 instance and using it to sign the PDF. 
As a workaround you can get the certificate from USB as X509Certificate2  and use this to sign the PDF using below code snippet: 
// Create a PdfCertificate instance with X509Certificate2 created from certificates stored on USB tokens 
PdfCertificate cert = new PdfCertificate(x509Certificate2); 
PdfDocument doc = new PdfDocument(); 
PdfPageBase page = doc.Pages.Add(); 
PdfGraphics graphics = page.Graphics; 
PdfSignature signature = new PdfSignature(doc, page, cert, "Signature"); 
signature.TimeStampServer = new TimeStampServer(new Uri("Time stamp server link")); 
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)); 
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14); 
graphics.DrawString("Hello world!", font, PdfBrushes.Black, new PointF(0, 0)); 
signature.EnableValidationAppearance = true; 
signature.EnableLtv = true; 

Kindly try the same and let us know if you need any further information. 

Surya Kumar 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon