Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies within .NET ( C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

Thu Jul 12, 2012 1:37 am


I am trying to add an annotation to a pdf document, and everything appears to work properly (no errors) until I go to save the document at which time I get a "Object reference not set to an instance of an object". If I comment out the page.AnnotationsWidget.Add command, the document saves without an error. I'm using version of the Spire.PDF package. Please tell me what I am doing wrong. Here is my code:

Code: Select all
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim doc As New PdfDocument("C:\temp\test.pdf")
        Dim doc2 As New PdfDocument
        Dim oAnn As PdfFreeTextAnnotation

        doc2.InsertPage(doc, 0)
        Dim page As PdfPageBase = doc2.Pages(0)

        'Draw the text
        page.Canvas.DrawString("Hello, World!", New PdfFont(PdfFontFamily.Helvetica, 30.0F), New PdfSolidBrush(Color.Black), 10, 10)

        oAnn = New PdfFreeTextAnnotation(New Rectangle(0, 0, 50, 35))
        With oAnn
            .Border = New PdfAnnotationBorder(1)
            .Color = Color.AliceBlue
            .MarkupText = "Test"
            .Flags = PdfAnnotationFlags.Default
        End With

    End Sub

Posts: 1
Joined: Mon Jul 09, 2012 7:51 pm

Thu Jul 12, 2012 6:57 am

Hi bsimkins,

Thank you for your report on the problem. We have defined it as a bug. We will fix it in next version of Spire.PDF. But it can solve your problem to set the following property:
Code: Select all
   .MarkupText = "sssss"
            .Font = New PdfFont(PdfFontFamily.Helvetica, 10)
            .CalloutLines = New PointF(1) {New PointF(0, 0), New PointF(10, 10)}

And I have writed a demo for you in the attachment. You can refer to it. If you still have any problems, welcome to contact us! Thank you for your cooperation and understanding.
You do not have the required permissions to view the files attached to this post.
e-iceblue support team
contact: nancy.wang@e-iceblue.com
User avatar

Posts: 51
Joined: Wed May 30, 2012 2:02 am

Return to Spire.PDF