Skip to footer content
USING IRONPDF

How to Create a VB.NET PDF Viewer with IronPDF: A Complete Tutorial

Displaying PDF documents directly inside VB.NET applications can still be tricky for many developers. The .NET Framework and .NET Core don’t provide built-in ways to view PDF files, so people often rely on old ActiveX controls or messy third-party tools. That can get frustrating for both developers and users.

If you’re building a Windows Forms or WPF application, you want something reliable for PDF viewing. Whether it’s invoices, reports, or even Word documents converted to PDF format, IronPDF simplifies this process by eliminating the need for external components and providing powerful options to create, edit, and process PDFs directly within your project.

In this tutorial, I’ll walk you step by step through building a VB.NET PDF viewer. By the end, you’ll know how to generate and display PDF documents in your app like an expert. Additionally, you’ll also see how easy it is to add features like zoom, navigation, and printing. I’ve tried this approach in a recent internal project, and it significantly sped up our team's report review process.

What Makes PDF Viewing in VB.NET Challenging?

The Visual Studio toolbox lacks a standard PDF viewer control. Developers often rely on Internet Explorer or embedded WebBrowser controls to display PDF files, but these approaches depend on the user's default PDF reader and can introduce hidden costs for deployment.

Traditional solutions may also require installing external software or manual configuration for proper PDF form handling, printing, or rendering, which increases complexity and limits the ability to customize the display of PDFs across multiple Windows environments.

How Does IronPDF Simplify PDF Viewing in VB.NET?

IronPDF transforms PDF handling in VB.NET applications by providing a self-contained library that doesn't require Adobe Reader or other external viewers. Beyond basic viewing, it enables developers to create, edit, manipulate, and render PDFs programmatically using familiar .NET patterns.

The library's architecture leverages a Chrome-based rendering engine, ensuring pixel-perfect display of complex PDFs with full support for modern features like forms, annotations, and embedded multimedia. This approach guarantees consistent rendering across all Windows environments.

Key capabilities include

  • Direct PDF rendering without download or browser dependencies
  • Conversion from Word documents or HTML to PDF format
  • Editing, splitting, and merging PDF pages
  • Filling and extracting PDF forms
  • Built-in printing support with customizable settings
  • Support for templates, images, and multi-page PDF files

These features make IronPDF a highly customizable solution for .NET applications, enabling developers to handle complex PDF documents in a desktop or web application environment.

How to Install IronPDF in Your VB.NET Project?

Setting up IronPDF requires just a few steps through NuGet Package Manager. Open your VB.NET Windows Forms project in Visual Studio and follow these steps:

  1. Open your new project in Visual Studio with your target framework or .NET Core.
  2. Right-click on your project in Solution Explorer
  3. Select "Manage NuGet Packages"
  4. Search for "IronPDF" in the Browse tab
  5. Click Install on the IronPDF package

After installation, add this import statement to your VB.NET files:

Imports IronPdf
Imports IronPdf
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This import statement gives your VB.NET project access to all IronPDF classes and methods, allowing you to load, render, print, and manipulate PDF documents programmatically.

This setup includes all necessary runtime components, eliminating manual configuration and avoiding hidden costs.

How to Create a Basic PDF Viewer in Windows Forms?

Building a PDF viewer starts with creating a Windows Forms application and implementing IronPDF's rendering capabilities. Here's a streamlined approach to display PDFs in your application:

Imports System.Drawing
Imports System.IO
Imports IronPdf
Public Class Form1
    Private currentPdf As PdfDocument
    Private pdfBitmaps() As Bitmap
    Private currentPage As Integer = 0
    Private zoomLevel As Double = 1.0
    ' Load PDF Button
    Private Sub LoadPdfButton_Click(sender As Object, e As EventArgs) Handles LoadPdfButton.Click
        Using openFileDialog As New OpenFileDialog()
            openFileDialog.Filter = "PDF Files (*.pdf)|*.pdf"
            If openFileDialog.ShowDialog() = DialogResult.OK Then
                ' Load PDF
                currentPdf = PdfDocument.FromFile(openFileDialog.FileName)
                ' Render all pages to image files
                Dim filePaths As String() = currentPdf.RasterizeToImageFiles("page_*.png")
                ' Load images into memory
                Dim pageList As New List(Of Bitmap)()
                For Each filePath As String In filePaths
                    Using ms As New MemoryStream(File.ReadAllBytes(filePath))
                        Dim bmp As New Bitmap(ms)
                        pageList.Add(bmp)
                    End Using
                Next
                pdfBitmaps = pageList.ToArray()
                currentPage = 0
                zoomLevel = 1.0
                DisplayCurrentPage()
            End If
        End Using
    End Sub
    ' Show the current page in PictureBox
    Private Sub DisplayCurrentPage()
        If pdfBitmaps IsNot Nothing AndAlso currentPage < pdfBitmaps.Length Then
            Dim bmp As Bitmap = pdfBitmaps(currentPage)
            ' Apply zoom
            Dim newWidth As Integer = CInt(bmp.Width * zoomLevel)
            Dim newHeight As Integer = CInt(bmp.Height * zoomLevel)
            Dim zoomedBmp As New Bitmap(bmp, newWidth, newHeight)
            PictureBox1.Image = zoomedBmp
        Else
            PictureBox1.Image = Nothing
        End If
        UpdateNavigationButtons()
    End Sub
Imports System.Drawing
Imports System.IO
Imports IronPdf
Public Class Form1
    Private currentPdf As PdfDocument
    Private pdfBitmaps() As Bitmap
    Private currentPage As Integer = 0
    Private zoomLevel As Double = 1.0
    ' Load PDF Button
    Private Sub LoadPdfButton_Click(sender As Object, e As EventArgs) Handles LoadPdfButton.Click
        Using openFileDialog As New OpenFileDialog()
            openFileDialog.Filter = "PDF Files (*.pdf)|*.pdf"
            If openFileDialog.ShowDialog() = DialogResult.OK Then
                ' Load PDF
                currentPdf = PdfDocument.FromFile(openFileDialog.FileName)
                ' Render all pages to image files
                Dim filePaths As String() = currentPdf.RasterizeToImageFiles("page_*.png")
                ' Load images into memory
                Dim pageList As New List(Of Bitmap)()
                For Each filePath As String In filePaths
                    Using ms As New MemoryStream(File.ReadAllBytes(filePath))
                        Dim bmp As New Bitmap(ms)
                        pageList.Add(bmp)
                    End Using
                Next
                pdfBitmaps = pageList.ToArray()
                currentPage = 0
                zoomLevel = 1.0
                DisplayCurrentPage()
            End If
        End Using
    End Sub
    ' Show the current page in PictureBox
    Private Sub DisplayCurrentPage()
        If pdfBitmaps IsNot Nothing AndAlso currentPage < pdfBitmaps.Length Then
            Dim bmp As Bitmap = pdfBitmaps(currentPage)
            ' Apply zoom
            Dim newWidth As Integer = CInt(bmp.Width * zoomLevel)
            Dim newHeight As Integer = CInt(bmp.Height * zoomLevel)
            Dim zoomedBmp As New Bitmap(bmp, newWidth, newHeight)
            PictureBox1.Image = zoomedBmp
        Else
            PictureBox1.Image = Nothing
        End If
        UpdateNavigationButtons()
    End Sub
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Code Explanation:

  • currentPdf stores the loaded PDF document.
  • pdfBitmaps holds bitmap images for each PDF page so they can be displayed in a PictureBox control.
  • LoadPdfButton_Click uses a standard OpenFileDialog to let users select a PDF file.
  • PdfDocument.FromFile loads the PDF document, and RasterizeToImageFiles converts each page to image files.
  • Each file is read into memory as a Bitmap, added to the array, and the first page is displayed with DisplayCurrentPage().

When we run the program, we'll be able to load a PDF file through the dialog pop-up when we click the "Load PDF" button.

How to Implement PDF Navigation Controls?

Navigation enhances user experience by allowing movement through multi-page documents. Add Previous and Next buttons to your form with this implementation:

' Next Page Button
Private Sub NextButton_Click(sender As Object, e As EventArgs) Handles NextButton.Click
    If currentPage < pdfBitmaps.Length - 1 Then
        currentPage += 1
        DisplayCurrentPage()
    End If
End Sub
' Previous Page Button
Private Sub PreviousButton_Click(sender As Object, e As EventArgs) Handles PreviousButton.Click
    If currentPage > 0 Then
        currentPage -= 1
        DisplayCurrentPage()
    End If
End Sub
' Next Page Button
Private Sub NextButton_Click(sender As Object, e As EventArgs) Handles NextButton.Click
    If currentPage < pdfBitmaps.Length - 1 Then
        currentPage += 1
        DisplayCurrentPage()
    End If
End Sub
' Previous Page Button
Private Sub PreviousButton_Click(sender As Object, e As EventArgs) Handles PreviousButton.Click
    If currentPage > 0 Then
        currentPage -= 1
        DisplayCurrentPage()
    End If
End Sub
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

These Private Sub procedures handle navigation through the PDF pages using Object sender, EventArgs e. Buttons update currentPage and call DisplayCurrentPage() to render the PDF page in the Windows Form.

' Update navigation controls and page label
Private Sub UpdateNavigationButtons()
    PreviousButton.Enabled = currentPage > 0
    NextButton.Enabled = currentPage < pdfBitmaps.Length - 1
    PageLabel.Text = $"Page {currentPage + 1} of {pdfBitmaps.Length}"
End Sub
' Update navigation controls and page label
Private Sub UpdateNavigationButtons()
    PreviousButton.Enabled = currentPage > 0
    NextButton.Enabled = currentPage < pdfBitmaps.Length - 1
    PageLabel.Text = $"Page {currentPage + 1} of {pdfBitmaps.Length}"
End Sub
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This updates the button states so users cannot navigate beyond the first or last page, while the label shows the current page number and total pages.

Output

How to Load PDF Files from Different Sources?

IronPDF supports loading PDFs from various sources beyond local files. This flexibility allows integration with databases, web services, and memory streams:

Loading from URL

' Load PDF from URL
Private Sub LoadUrlButton_Click(sender As Object, e As EventArgs) Handles LoadUrlButton.Click
    Dim url As String = UrlTextBox.Text.Trim()
    If String.IsNullOrEmpty(url) Then
        MessageBox.Show("Please enter a valid URL.")
        Return
    End If
    Try
        LoadFromUrl(url)
    Catch ex As Exception
        MessageBox.Show("Failed to load PDF: " & ex.Message)
    End Try
End Sub
' Load PDF from URL
Private Sub LoadUrlButton_Click(sender As Object, e As EventArgs) Handles LoadUrlButton.Click
    Dim url As String = UrlTextBox.Text.Trim()
    If String.IsNullOrEmpty(url) Then
        MessageBox.Show("Please enter a valid URL.")
        Return
    End If
    Try
        LoadFromUrl(url)
    Catch ex As Exception
        MessageBox.Show("Failed to load PDF: " & ex.Message)
    End Try
End Sub
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This Private Sub checks the URL input, displays an alert if invalid, and calls LoadFromUrl to render the PDF dynamically.

Private Sub LoadFromUrl(url As String)
    Dim renderer As New ChromePdfRenderer()
    renderer.RenderingOptions.EnableJavaScript = True
    renderer.RenderingOptions.CssMediaType = Rendering.PdfCssMediaType.Print
    renderer.RenderingOptions.WaitFor.JavaScript(3000)
    currentPdf = renderer.RenderUrlAsPdf(url)
    LoadPdfBitmaps()
End Sub
Private Sub LoadFromUrl(url As String)
    Dim renderer As New ChromePdfRenderer()
    renderer.RenderingOptions.EnableJavaScript = True
    renderer.RenderingOptions.CssMediaType = Rendering.PdfCssMediaType.Print
    renderer.RenderingOptions.WaitFor.JavaScript(3000)
    currentPdf = renderer.RenderUrlAsPdf(url)
    LoadPdfBitmaps()
End Sub
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This uses ChromePdfRenderer to convert a web page URL into a PDF document. Options allow JavaScript execution and print-friendly CSS, then the PDF pages are loaded as bitmaps..

Output

How to Create a VB.NET PDF Viewer with IronPDF: A Complete Tutorial: Figure 3 - URL to PDF displayed with PDF viewer

Loading from HTML Content

Private Sub LoadHtmlButton_Click(sender As Object, e As EventArgs) Handles LoadHtmlButton.Click
    Dim htmlContent As String = "<html><body><h1>Hello PDF!</h1><p>This is a hardcoded HTML PDF test.</p></body></html>"
    LoadFromHtml(htmlContent)
End Sub
Private Sub LoadFromHtml(htmlContent As String)
    Dim renderer As New ChromePdfRenderer()
    currentPdf = renderer.RenderHtmlAsPdf(htmlContent)
    LoadPdfBitmaps()
End Sub
Private Sub LoadHtmlButton_Click(sender As Object, e As EventArgs) Handles LoadHtmlButton.Click
    Dim htmlContent As String = "<html><body><h1>Hello PDF!</h1><p>This is a hardcoded HTML PDF test.</p></body></html>"
    LoadFromHtml(htmlContent)
End Sub
Private Sub LoadFromHtml(htmlContent As String)
    Dim renderer As New ChromePdfRenderer()
    currentPdf = renderer.RenderHtmlAsPdf(htmlContent)
    LoadPdfBitmaps()
End Sub
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This example converts HTML content to PDF using the RenderHtmlAsPdf method. This process is ideal for dynamic reports or templates.

Output

How to Create a VB.NET PDF Viewer with IronPDF: A Complete Tutorial: Figure 4 - HTML to PDF displayed in PDF viewer

These methods enable dynamic PDF generation and viewing without temporary files, improving performance and security.

How to Add Zoom Functionality?

Zoom controls improve readability for detailed documents. Implement zoom using image scaling:

Private Sub ZoomInButton_Click(sender As Object, e As EventArgs) Handles ZoomInButton.Click
        zoomLevel = Math.Min(zoomLevel + 0.25, 3.0)
        DisplayCurrentPage()
    End Sub
    Private Sub ZoomOutButton_Click(sender As Object, e As EventArgs) Handles ZoomOutButton.Click
        zoomLevel = Math.Max(zoomLevel - 0.25, 0.5)
        DisplayCurrentPage()
    End Sub
    Private Sub ApplyZoom()
        If pdfBitmaps IsNot Nothing AndAlso currentPage < pdfBitmaps.Length Then
            Dim pageImage As Bitmap = pdfBitmaps(currentPage)
            Dim newWidth As Integer = CInt(pageImage.Width * zoomLevel)
            Dim newHeight As Integer = CInt(pageImage.Height * zoomLevel)
            Dim zoomedImage As New Bitmap(pageImage, newWidth, newHeight)
            PictureBox1.Image = zoomedImage
        Else
            PictureBox1.Image = Nothing
        End If
    End Sub
Private Sub ZoomInButton_Click(sender As Object, e As EventArgs) Handles ZoomInButton.Click
        zoomLevel = Math.Min(zoomLevel + 0.25, 3.0)
        DisplayCurrentPage()
    End Sub
    Private Sub ZoomOutButton_Click(sender As Object, e As EventArgs) Handles ZoomOutButton.Click
        zoomLevel = Math.Max(zoomLevel - 0.25, 0.5)
        DisplayCurrentPage()
    End Sub
    Private Sub ApplyZoom()
        If pdfBitmaps IsNot Nothing AndAlso currentPage < pdfBitmaps.Length Then
            Dim pageImage As Bitmap = pdfBitmaps(currentPage)
            Dim newWidth As Integer = CInt(pageImage.Width * zoomLevel)
            Dim newHeight As Integer = CInt(pageImage.Height * zoomLevel)
            Dim zoomedImage As New Bitmap(pageImage, newWidth, newHeight)
            PictureBox1.Image = zoomedImage
        Else
            PictureBox1.Image = Nothing
        End If
    End Sub
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This code adjusts the zoomLevel in steps and calls DisplayCurrentPage() to apply zoom scaling for improved readability on the desktop

How to Print PDF Documents?

Printing functionality completes the viewer experience. IronPDF simplifies printing with built-in methods:

Private Sub PrintButton_Click(sender As Object, e As EventArgs) Handles PrintButton.Click
        If currentPdf IsNot Nothing Then
            ' Simple print with default settings
            currentPdf.Print()
            ' Or with custom settings
            Dim printDoc As PrintDocument = currentPdf.GetPrintDocument()
            Using printDialog As New PrintDialog()
                printDialog.Document = printDoc
                If printDialog.ShowDialog() = DialogResult.OK Then
                    printDoc.Print()
                End If
            End Using
        End If
    End Sub
Private Sub PrintButton_Click(sender As Object, e As EventArgs) Handles PrintButton.Click
        If currentPdf IsNot Nothing Then
            ' Simple print with default settings
            currentPdf.Print()
            ' Or with custom settings
            Dim printDoc As PrintDocument = currentPdf.GetPrintDocument()
            Using printDialog As New PrintDialog()
                printDialog.Document = printDoc
                If printDialog.ShowDialog() = DialogResult.OK Then
                    printDoc.Print()
                End If
            End Using
        End If
    End Sub
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This Private Sub allows users to print the PDF document with default or custom printer settings. GetPrintDocument() returns a PrintDocument object for integration with Windows Forms PrintDialog.

How to Implement PDF Viewing in WPF Applications?

While Windows Forms dominates desktop development, WPF applications can also leverage IronPDF. The approach differs slightly:

' In WPF Window code-behind
Private Sub LoadPdfInWpf(filePath As String)
    Dim pdfDoc As PdfDocument = PdfDocument.FromFile(filePath)
    Dim pageImage As Bitmap = pdfDoc.ToBitmap(0)
    ' Convert to WPF-compatible image
    Dim bitmapImage As New BitmapImage()
    Using memory As New MemoryStream()
        pageImage.Save(memory, ImageFormat.Png)
        memory.Position = 0
        bitmapImage.BeginInit()
        bitmapImage.StreamSource = memory
        bitmapImage.CacheOption = BitmapCacheOption.OnLoad
        bitmapImage.EndInit()
    End Using
    ImageControl.Source = bitmapImage
End Sub
' In WPF Window code-behind
Private Sub LoadPdfInWpf(filePath As String)
    Dim pdfDoc As PdfDocument = PdfDocument.FromFile(filePath)
    Dim pageImage As Bitmap = pdfDoc.ToBitmap(0)
    ' Convert to WPF-compatible image
    Dim bitmapImage As New BitmapImage()
    Using memory As New MemoryStream()
        pageImage.Save(memory, ImageFormat.Png)
        memory.Position = 0
        bitmapImage.BeginInit()
        bitmapImage.StreamSource = memory
        bitmapImage.CacheOption = BitmapCacheOption.OnLoad
        bitmapImage.EndInit()
    End Using
    ImageControl.Source = bitmapImage
End Sub
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

What Are the Best Practices for PDF Viewer Performance?

Optimizing PDF viewing ensures a smooth user experience:

Memory Management

Always dispose of PDF documents when finished:

Protected Overrides Sub OnFormClosed(e As FormClosedEventArgs)
    If currentPdf IsNot Nothing Then
        currentPdf.Dispose()
    End If
    MyBase.OnFormClosed(e)
End Sub
Protected Overrides Sub OnFormClosed(e As FormClosedEventArgs)
    If currentPdf IsNot Nothing Then
        currentPdf.Dispose()
    End If
    MyBase.OnFormClosed(e)
End Sub
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Asynchronous Loading

IronPDF additionally supports asynchronous loading, useful to load large PDFs without freezing the UI:

Private Async Sub LoadPdfAsync(filePath As String)
    LoadingLabel.Visible = True
    Await Task.Run(Sub()
        currentPdf = PdfDocument.FromFile(filePath)
    End Sub)
    LoadingLabel.Visible = False
    DisplayCurrentPage()
End Sub
Private Async Sub LoadPdfAsync(filePath As String)
    LoadingLabel.Visible = True
    Await Task.Run(Sub()
        currentPdf = PdfDocument.FromFile(filePath)
    End Sub)
    LoadingLabel.Visible = False
    DisplayCurrentPage()
End Sub
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Conclusion

Building a PDF viewer in VB.NET with IronPDF eliminates the complexity of traditional approaches while providing professional features. From basic file viewing to advanced PDF form processing and printing, IronPDF handles all aspects of PDF interaction within your Windows Forms applications.

Whether displaying reports, processing forms, or implementing document management systems, IronPDF provides the tools, support, and license options needed for comprehensive PDF solutions.

Start your VB.NET PDF viewer project with IronPDF's free trial to explore all features. Scale to production deployments with flexible licensing. For detailed API documentation and additional examples, visit the IronPDF documentation and explore the comprehensive VB.NET code samples.

NuGet Install with NuGet

PM >  Install-Package IronPdf

Check out IronPDF on NuGet for quick installation. With over 10 million downloads, it’s transforming PDF development with C#. You can also download the DLL or Windows installer.

Frequently Asked Questions

How can I create a PDF viewer in VB.NET?

You can create a PDF viewer in VB.NET using IronPDF. It allows you to open, view, zoom, navigate, print, and save PDF pages easily within your .NET applications.

What challenges do developers face when displaying PDFs in VB.NET?

Developers often face challenges because the .NET Framework and .NET Core do not provide built-in methods to view PDF files, leading many to rely on outdated ActiveX controls or complex third-party tools.

Can IronPDF be used with both .NET Framework and .NET Core?

Yes, IronPDF is compatible with both .NET Framework and .NET Core, making it a versatile choice for developing PDF viewing applications in VB.NET.

What features does IronPDF offer for PDF viewing?

IronPDF offers features such as opening, viewing, zooming, navigating, printing, and saving PDF pages, enhancing the user experience when interacting with PDF documents in VB.NET applications.

Why should I avoid using ActiveX controls for PDF viewing in VB.NET?

ActiveX controls are often outdated and can lead to messy implementations. Using modern libraries like IronPDF provides a more streamlined and reliable solution for PDF viewing in VB.NET.

Is it possible to print PDF documents using IronPDF in VB.NET?

Yes, IronPDF allows you to print PDF documents directly from your VB.NET application, providing a seamless experience for users needing hard copies of their documents.

How does IronPDF improve the PDF viewing experience for users?

IronPDF improves the PDF viewing experience by providing easy-to-use features for interacting with PDFs, such as smooth navigation, zooming capabilities, and the ability to save and print documents effortlessly.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More