How to Parse PDF File in VB.NET

This tutorial introduces how to programmatically extract texts and images from PDF files with first-class support from IronPDF.

IronPDF

Features

Efficient PDF conversion. Almost anything a machine can do, IronPDF can as well. Thanks to this PDF library, developers can quickly create, read text content, write, load and manipulate PDF.

IronPDF converts HTML into a PDF record with the aid of using the Chrome engine. Along with Windows Forms, HTML, ASPX, Razor HTML, .NET Core, ASP.NET, Windows Forms, and WPF. IronPDF also supports Xamarin, Blazor, Unity, and HoloLense applications. IronPDF supports both Microsoft .NET and .NET Core applications (Both ASP.NET Web packages and conventional Windows packages). IronPDF can be used to make aesthetically appealing PDFs.

IronPDF can create a PDF using HTML5, JavaScript, CSS, and images. IronPDF also has a powerful HTML-to-PDF converter that integrates with PDF. A strong PDF conversion mechanism is present in IronPDF using the Chromium rendering engine. It is also unconnected to any outside sources.

  • A PDF image can be created from a variety of sources, including HTML, HTML5, ASPX, and Razor/MVC View. Both HTML and image assets can be converted to PDF.
  • Tools that can be used to work with interactive PDFs include filling out and submitting interactive forms.
  • Merge and divide PDFs, extract text and pictures from PDF files, search text in PDF files, rasterize PDFs to images, change font size and convert PDF files.
  • It allows for the verification of HTML login forms using user-agents, proxies, cookies, HTTP headers, and form variables.
  • Accessing secured documents is made possible by IronPDF by giving user names and passwords.
  • IronPDF is a program that reads text in PDF and completes the gaps.
  • Allows to add text, images, bookmarks, watermarks, and more.
  • You can create a PDF file from a CSS file.

For more details, visit this page for a free limited key and professional version.

How to Parse PDF File in VB.NET, Figure 1: IronPDF- Font formatting IronPDF- Font formatting

Extract text from PDF file

IronPDF can also read and extract text from PDF files with the help of the IronPDF libraries. Below is a pattern of IronPDF code that may be used to examine present PDF files.

Extract Text From All Pages

The code example below demonstrates the first method to acquire all the PDF content as a string with just a few lines.

Imports IronPdf
Module Program
    Sub Main(args As String())
        Dim AllText As String
        Dim pdfdoc = PdfDocument.FromFile("result.pdf")
        AllText = pdfdoc.ExtractAllText()
        Console.WriteLine(AllText)
    End Sub
End Module
Imports IronPdf
Module Program
    Sub Main(args As String())
        Dim AllText As String
        Dim pdfdoc = PdfDocument.FromFile("result.pdf")
        AllText = pdfdoc.ExtractAllText()
        Console.WriteLine(AllText)
    End Sub
End Module
VB.NET

The sample code above demonstrates how to use the FromFile method to read a PDF from an existing file and convert it into a PDF document object. The object provides a method called ExtractAllText that will extract plain text from the PDF and turn it into a string.

Extract Text by Page Number

Below sample code below shows how to extract data from a PDF file using the page number.

Imports IronPdf
Module Program
Sub Main(args       As String())
    Dim AllText     As String
    Dim pdfdoc = PdfDocument.FromFile("result.pdf")
    AllText = pdfdoc.ExtractTextFromPage(0)
    Console.WriteLine(AllText)
End Sub
End Module
Imports IronPdf
Module Program
Sub Main(args       As String())
    Dim AllText     As String
    Dim pdfdoc = PdfDocument.FromFile("result.pdf")
    AllText = pdfdoc.ExtractTextFromPage(0)
    Console.WriteLine(AllText)
End Sub
End Module
VB.NET

The code above shows how to read a PDF from an existing file and turn it into a PDF document object using the FromFile function. Texts and images can be accessed on the PDF using this object. The object offers a method called ExtractTextFromPage that allows to send a page number as a parameter to get a string that contains every word that was on the page of the PDF.

Extract Text Between Pages

The below code shows how to extract the data between multiple pages.

Imports IronPdf
Module Program
Sub Main(args       As String())
    Dim Pages       As List(Of Integer) = New List(Of Integer)
    Pages.Add(3)
    Pages.Add(5)
    Pages.Add(7)
    Dim AllText     As String
    Dim pdfdoc = PdfDocument.FromFile("result.pdf")
    AllText = pdfdoc.ExtractTextFromPages(Pages)
    Console.WriteLine(AllText)

End Sub
End Module
Imports IronPdf
Module Program
Sub Main(args       As String())
    Dim Pages       As List(Of Integer) = New List(Of Integer)
    Pages.Add(3)
    Pages.Add(5)
    Pages.Add(7)
    Dim AllText     As String
    Dim pdfdoc = PdfDocument.FromFile("result.pdf")
    AllText = pdfdoc.ExtractTextFromPages(Pages)
    Console.WriteLine(AllText)

End Sub
End Module
VB.NET

The code above demonstrates how to use the FromFile method to read a PDF from an existing file and convert it into a PDF document object. This object allows examine the text and images on PDF. The object has a method called ExtractTextFromPages can be used to get a string that includes all the text content on a given page of the document by passing a list of page numbers as a parameter. Below the left side is the source PDF and the right side is the data extracted.

How to Parse PDF File in VB.NET, Figure 2: Extract text between pages output Extract text between pages output

Extract Image from PDF file

IronPDF provides a list of methods to extract images such as:

Each method allows to extract images from a page or multiple pages of the document.

Dim pdfdoc = PdfDocument.FromFile("result.pdf")
Dim images = pdfdoc.ExtractRawImagesFromPage(1)
For Each            As Byte() In images
    Dim ms          As New IO.MemoryStream(CType(, Byte()))
    Dim image = New Bitmap(ms)
    image.Save("output//test.jpg")
Next
Dim pdfdoc = PdfDocument.FromFile("result.pdf")
Dim images = pdfdoc.ExtractRawImagesFromPage(1)
For Each            As Byte() In images
    Dim ms          As New IO.MemoryStream(CType(, Byte()))
    Dim image = New Bitmap(ms)
    image.Save("output//test.jpg")
Next
VB.NET

The code above shows how to read a document from an existing file and turn it into a PDF document object using the FromFile function. By passing a list of page numbers to the object's ExtractRawImagesFromPage method, a list of bytes can be obtained that contains every picture that was present on a given page of the document. Using a foreach loop to handle each byte and turn it into a memory stream. Then into a bitmap, which aids in picture saving. The below image shows the output from the above code.

How to Parse PDF File in VB.NET, Figure 3: Extract Images from PDF output Extract Images from PDF output

To know more about the IronPDF API code tutorial, refer to the documentation pages. You can also visit other tutorials to learn how to parse PDF text using C#.

Conclusion

The development license for the library IronPDF is gratis. If using IronPDF in a production environment, different licenses can be bought depending on the developer's needs. The Lite plan starts at $749 and has no ongoing costs. SaaS and OEM redistribution alternatives are also provided. All licenses include updates, a year of product support and a permanent license. They are also useful for manufacturing, staging, and development. It is a one-time purchase. There are additional free, time-limited licenses accessible. Visit this licensing page to read the complete pricing and licensing details for IronPDF. IronPDF also provides free licenses for copy protection.