Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

489
Views
Is iText7 available in VB.Net or only C#

I want to extract text fields content from pdf files which have text fields that I need to bring into my Winforms project. Searching I found reference to iTextSharp but then saw that it is replaced with iText7 but everything I read refers only to it being used in C#. My winforms project is vb. Any pointers as to what would be my best option to achieve getting that data into my project is much appreciated

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

If it's available for .NET then it's available for all .NET languages. That's one of the useful things about the way the .NET Framework works - it doesn't matter which programming language a particular library or project was written in. Once it's compiled to a .NET assembly DLL it can be used from any other .NET language regardless.

If, for example, iTextSharp or iText7 is available as Nuget package (which I believe they are) then it's especially simple - you can just install the package into your VB.NET project and use it.

You may often find that usage examples are written in one specific language, but that doesn't mean you can't make exactly the same class instantions, method calls etc using a different language. If you struggle with translating code samples from one language to another there are free automatic code converters available online (especially between C# and VB.NET and vice-versa) which will usually do 90-100% of the conversion work for you.

over 4 years ago · Santiago Trujillo Report

0

To extract text from a PDF file using itext7, try the following:

Pre-requisite: Download/install NuGet package itext7

Add the following Imports statements:

Imports iText.Kernel.Pdf
Imports iText.Kernel.Pdf.Canvas.Parser.Listener
Imports iText.Kernel.Pdf.Canvas.Parser.PdfTextExtractor

GetTextFromPdf:

Public Function GetTextFromPdf(filename As String) As String
    Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()

    Using doc As PdfDocument = New PdfDocument(New PdfReader(filename))
        'Dim strategy As LocationTextExtractionStrategy = New LocationTextExtractionStrategy()

        For i As Integer = 1 To doc.GetNumberOfPages() Step 1
            Dim page = doc.GetPage(i)
            'Dim text = iText.Kernel.Pdf.Canvas.Parser.PdfTextExtractor.GetTextFromPage(page, strategy)
            Dim text = GetTextFromPage(page)
            sb.AppendLine(text)
        Next
    End Using

    Return sb.ToString()
End Function

The code for GetTextFromPdf is adapted from here.

Update:

The code below shows how to read the field names and field values from an AcroForm in a Pdf document:

Add the following Imports statements:

Imports iText.Forms
Imports iText.Kernel.Pdf

GetTextFromPdfFields

Public Function GetTextFromPdfFields(filename As String) As String
    Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()

    'create new instance
    Using doc As PdfDocument = New PdfDocument(New PdfReader(filename))

        'get AcroForm from document
        Dim form As PdfAcroForm = PdfAcroForm.GetAcroForm(doc, True)

        'get form fields
        Dim fieldDict As IDictionary(Of String, Fields.PdfFormField) = form.GetFormFields()

        'loop through form fields
        For Each kvp As KeyValuePair(Of String, Fields.PdfFormField) In fieldDict
            Dim type As PdfName = form.GetField(kvp.Key).GetFormType()
            Dim fieldName As PdfString = form.GetField(kvp.Key).GetFieldName()
            Dim fieldValue As String = form.GetField(kvp.Key).GetValueAsString()

            If fieldName IsNot Nothing Then
                'append data to instance of StringBuilder
                sb.AppendLine("Type: " & type.ToString() & " FieldName: " & fieldName.ToString() & " Value: " & fieldValue)
            End If
        Next
    End Using

    Return sb.ToString()
End Function

**Note: The code for GetTextFromPdfFields is adapted from here.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!