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.

Thu Dec 16, 2021 2:27 am

Good Morning :) How can I extract annotations from a pdf file and store it on a richtextbox? im using VB.net

Twentyf4
 
Posts: 18
Joined: Thu Dec 16, 2021 2:23 am

Thu Dec 16, 2021 6:02 am

Hello,

Thank you for your inquiry.
Please use the following code to get the annotations in the PDF file and store them in the richtextbox. If this code does not meet your needs, please provide your sample PDF file for our reference. You could attach it here or send it to us via email (support@e-iceblue.com). Thanks in advance.
Code: Select all
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
    'Create a new PDF document.
    Dim pdf As New PdfDocument()
    'Load the file from disk.
    pdf.LoadFromFile("input.pdf")
   Dim content As New StringBuilder()
    For Each pdfPage As PdfPageBase In pdf.Pages
      'Get all annotations from the pdfPage.
      Dim annotations As PdfAnnotationCollection = pdfPage.AnnotationsWidget
      For i As Integer = 0 To annotations.Count - 1
        'A text annotation will attach a popup annotation since they are father-son relationship.
        'The annotation information exists in the text annotation, so here we mask the blank popup annotation.
        If TypeOf annotations(i) Is PdfPopupAnnotationWidget Then
            Continue For
        End If
        content.AppendLine("Text: " & annotations(i).Text)
        Dim modifiedDate As String = annotations(i).ModifiedDate.ToString()
        content.AppendLine("ModifiedDate: " & modifiedDate)
    Next i
   Next
   Me.richTextBox1.Text = content.ToString
End Sub

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Thu Dec 16, 2021 6:08 am

Thanks for your reply but i want 1 text annotation 1 rich textbox? can you help me with this problem?

Twentyf4
 
Posts: 18
Joined: Thu Dec 16, 2021 2:23 am

Thu Dec 16, 2021 7:18 am

Hello,

Thank you for your feedback.
Please use the following code to achieve your requirement.
Code: Select all
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim pdf As PdfDocument = New PdfDocument
    pdf.LoadFromFile("input.pdf")
    Dim counts As Integer = 0
    For Each pdfPage As PdfPageBase In pdf. Pages
        Dim annotations As PdfAnnotationCollection = pdfPage. AnnotationsWidget
         For i As Integer = 0 To annotations. Count - 1
            Dim content As StringBuilder = New StringBuilder
            If TypeOf annotations(i) Is PdfPopupAnnotationWidget Then
                Continue For
            End If
            content.AppendLine(annotations(i).Text)
            Dim modifiedDate As String = annotations(i).ModifiedDate.ToString
            content.AppendLine(modifiedDate)
            Dim richTextBox As RichTextBox = New RichTextBox
            richTextBox. Name = ("richTextBox" + counts)
            richTextBox. Text = content. ToString
            richTextBox. Width = 300
            richTextBox. Height = 40
            richTextBox. Location = New Point(32, (20  _
                            + (counts * 50)))
            Me.Controls.Add(richTextBox)
            counts = (counts + 1)
            Next i
    Next
End Sub

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Thu Dec 16, 2021 8:28 am

it says 'Conversion from string "richTextBox" to type 'Double' is not valid.' :(

Twentyf4
 
Posts: 18
Joined: Thu Dec 16, 2021 2:23 am

Thu Dec 16, 2021 8:31 am

it has error 'Conversion from string "richTextBox" to type 'Double' is not valid.'

Twentyf4
 
Posts: 18
Joined: Thu Dec 16, 2021 2:23 am

Thu Dec 16, 2021 9:08 am

Hello,

Thank you for your feedback.
Kindly note that if you want to convert "richTextBox. Text" from String type to Double type, "richTextBox. Text" must contain only numbers. This means that the content of the annotations you get can only be numbers. and fill them in the rich text box. Please delete the following two lines of code in the code I provided.
Code: Select all
Dim modifiedDate As String = annotations(i).ModifiedDate.ToString
content.AppendLine(modifiedDate)

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Thu Dec 23, 2021 8:57 am

Hi,

Hope you are doing well!
How is your issue going? Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Mon Dec 27, 2021 2:01 am

But there are comments that contains numbers? How can i display it the the richtextbox?? And also i want a button inside a rich textbox that has update,delete and reply if he will click update the richtextbox will be enabled and can update the comment and when tthe user press delete it will delete the comment amd if the user press reply button there will be a textbox that appear i hope you will help me with.my problem

Twentyf4
 
Posts: 18
Joined: Thu Dec 16, 2021 2:23 am

Mon Dec 27, 2021 5:44 am

Hello,

Thank you for your feedback.
The comments of the PDF file can contain numbers. Please refer to the code below to display the comments with numbers in the rich textbox.
Code: Select all
annotations(i).Text = "1.1"
content.AppendLine(annotations(i).Text)
Dim richTextBox As RichTextBox = New RichTextBox
richTextBox.Name = ("richTextBox" + counts)
richTextBox.Text = content. ToString
'Convert String type to Double type
Dim numDouble As Double = Convert.ToDouble(richTextBox.Text)

In addition, you mentioned adding buttons in the rich textbox, this operation needs to be done by yourself. The operation code corresponding to the button is as follows:
Code: Select all
' Update the annotation from PDF document
pdf.Pages(0).AnnotationsWidget(0).Text = "New Annotations"
' Delete the annotation from PDF document
pdf.Pages(0).AnnotationsWidget.RemoveAt(0)

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Mon Dec 27, 2021 8:36 am

I already solve it but the remaining problem is the buttons :( ill try it myself

Twentyf4
 
Posts: 18
Joined: Thu Dec 16, 2021 2:23 am

Mon Dec 27, 2021 8:49 am

Hello,

Thanks for your feedback.
Any question, just feel free to contact us.

Have a nice day!

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Tue Dec 28, 2021 2:04 am

I encountered a problem that when im adding a text annotation and save it i encountered an error saying "'Access to the path 'C:\Users\AugustParas\AppData\Local\Temp\0826_001.pdf' is denied.'" can you help me with this error?

Twentyf4
 
Posts: 18
Joined: Thu Dec 16, 2021 2:23 am

Tue Dec 28, 2021 3:28 am

Hello,

Thank you for your feedback.
According to the program error message you provided, the issue should be caused by you without permission to access "0826_001.pdf". Please check the access permissions of this file.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Tue Dec 28, 2021 4:27 am

also what if i only want to display on the richtextbox is text annotation no stamp annotation ?

Twentyf4
 
Posts: 18
Joined: Thu Dec 16, 2021 2:23 am

Return to Spire.PDF