Skip to footer content
USING IRONPDF

VB .NET Display PDF in PictureBox: Render PDF Pages as Images in Windows Forms

Displaying PDF Files in a PictureBox Control

Displaying PDF files directly in a PictureBox control isn't possible because PictureBox only supports image formats like BMP, PNG, TIF, and JPG. The solution is to render PDF pages as bitmap images and then display them in Windows Forms applications.

In this tutorial, we'll show you how to convert and display PDF documents using IronPDF's powerful rasterization capabilities. If you need any further references or have answers to questions not covered, let me note that you can usually find more information in the official IronPDF references documentation.

Get stated with IronPDF now.
green arrow pointer

Why Can't PictureBox Display PDF Files Directly?

The PictureBox control in Microsoft .NET Framework Windows Forms applications is designed to display image files only. When developers attempt to load a PDF document into a PictureBox, they encounter errors because the PDF format requires specialized rendering. While some solutions involve using Adobe Reader or Adobe PDF Reader through COM components, this approach creates dependencies on external software like Adobe Acrobat. There is often another way to solve program limitations.

A cleaner approach uses IronPDF to render each PDF page as a bitmap image. This method works in any .NET application without requiring users to download or install Adobe Acrobat on their desktop systems. The process converts PDF pages to image formats that PictureBox can display natively, supporting output to PNG, TIF, and other standard formats.

How to Set Up a Windows Form Project for a PDF Viewer?

Create a new Windows Forms Application project in Visual Studio. Add a PictureBox control from the toolbox to the form, along with navigation buttons for browsing pages. Install IronPDF via NuGet Package Manager by searching for "IronPdf" and clicking install.

VB .NET Display PDF in PictureBox: Render PDF Pages as Images in Windows Forms: Image 1 - Install IronPDF

This SDK provides all the methods needed to load, render, and convert PDF files to images.

The following code example shows the basic form setup with controls for VB NET display PDF in PictureBox functionality:

Imports IronPDF
Imports System.Drawing

Public Class PdfViewerForm
    Private currentPdf As PdfDocument
    Private currentPageIndex As Integer = 0
    Private pageImages() As IronSoftware.Drawing.AnyBitmap

    Private Sub PdfViewerForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Form initialization code
        PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
    End Sub
End Class
Imports IronPDF
Imports System.Drawing

Public Class PdfViewerForm
    Private currentPdf As PdfDocument
    Private currentPageIndex As Integer = 0
    Private pageImages() As IronSoftware.Drawing.AnyBitmap

    Private Sub PdfViewerForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Form initialization code
        PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
    End Sub
End Class
VB .NET

Blank Form UI Example

VB .NET Display PDF in PictureBox: Render PDF Pages as Images in Windows Forms: Image 2 - Example blank windows form ready for use

This code establishes the foundation for the PDF viewer control. The PdfDocument object holds the loaded PDF document, while pageImages stores the rendered bitmap images for each PDF page. The SizeMode property enables automatic zoom scaling when displaying pages. This is a crucial foundation for the entire program.

How to Load and Display PDF Pages in a PictureBox?

Loading and displaying PDF documents requires converting each PDF page to a bitmap that PictureBox can render. IronPDF's ToBitmap method handles this conversion process efficiently, supporting various image formats and quality settings.

Private Sub LoadPdfDocument(filePath As String)
    ' Load the PDF document from file path
    currentPdf = PdfDocument.FromFile(filePath)
    ' Convert all PDF pages to bitmap images
    pageImages = currentPdf.ToBitmap()
    ' Display the first page
    If pageImages IsNot Nothing AndAlso pageImages.Length > 0 Then
        DisplayPage(0)
    End If
End Sub

Private Sub DisplayPage(pageIndex As Integer)
    If pageImages IsNot Nothing AndAlso pageIndex < pageImages.Length Then
        ' Create new Bitmap from the rendered page
        Dim newBitmap As New Bitmap(pageImages(pageIndex).GetStream())
        PictureBox1.Image = newBitmap
        currentPageIndex = pageIndex
        lblPageNumber.Text = $"Page {pageIndex + 1} of {pageImages.Length}"
    End If
End Sub

Private Sub btnOpen_Click(sender As Object, e As EventArgs) Handles btnOpen.Click
    Using openDialog As New OpenFileDialog()
        openDialog.Filter = "PDF Files|*.pdf"
        If openDialog.ShowDialog() = DialogResult.OK Then
            LoadPdfDocument(openDialog.FileName)
        End If
    End Using
End Sub
Private Sub LoadPdfDocument(filePath As String)
    ' Load the PDF document from file path
    currentPdf = PdfDocument.FromFile(filePath)
    ' Convert all PDF pages to bitmap images
    pageImages = currentPdf.ToBitmap()
    ' Display the first page
    If pageImages IsNot Nothing AndAlso pageImages.Length > 0 Then
        DisplayPage(0)
    End If
End Sub

Private Sub DisplayPage(pageIndex As Integer)
    If pageImages IsNot Nothing AndAlso pageIndex < pageImages.Length Then
        ' Create new Bitmap from the rendered page
        Dim newBitmap As New Bitmap(pageImages(pageIndex).GetStream())
        PictureBox1.Image = newBitmap
        currentPageIndex = pageIndex
        lblPageNumber.Text = $"Page {pageIndex + 1} of {pageImages.Length}"
    End If
End Sub

Private Sub btnOpen_Click(sender As Object, e As EventArgs) Handles btnOpen.Click
    Using openDialog As New OpenFileDialog()
        openDialog.Filter = "PDF Files|*.pdf"
        If openDialog.ShowDialog() = DialogResult.OK Then
            LoadPdfDocument(openDialog.FileName)
        End If
    End Using
End Sub
VB .NET

PDF Displayed in Form

VB .NET Display PDF in PictureBox: Render PDF Pages as Images in Windows Forms: Image 3 - Example input PDF displayed in our viewer

The LoadPdfDocument method uses PdfDocument.FromFile to load PDF files from a specified path, using the filename selected by the user. The ToBitmap method then converts all pages to bitmap images in a single operation. Each bitmap can be assigned directly to the PictureBox's Image property for display. This approach handles multi-page PDF documents by storing all rendered pages in an array. You can also edit the appearance of the form by clicking on the appropriate tab in the Visual Studio designer.

How to Navigate Between PDF Pages?

Implementing page navigation allows users to browse through all pages of a PDF document. The following code example demonstrates previous and next button functionality:

Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click
    If currentPageIndex > 0 Then
        DisplayPage(currentPageIndex - 1)
    End If
End Sub

Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
    If pageImages IsNot Nothing AndAlso currentPageIndex < pageImages.Length - 1 Then
        DisplayPage(currentPageIndex + 1)
    End If
End Sub
Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click
    If currentPageIndex > 0 Then
        DisplayPage(currentPageIndex - 1)
    End If
End Sub

Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
    If pageImages IsNot Nothing AndAlso currentPageIndex < pageImages.Length - 1 Then
        DisplayPage(currentPageIndex + 1)
    End If
End Sub
VB .NET

Output

VB .NET Display PDF in PictureBox: Render PDF Pages as Images in Windows Forms: Image 4 - Navigating to page 2 with our buttons

These event handlers check bounds before navigating to prevent errors. The IsNot Nothing check ensures the PDF document has been loaded before attempting navigation. This pattern works well for building a complete PDF viewer with support for displaying multiple pages.

How to Add Functionality to Save and Print PDF Documents?

Many Windows Forms applications need to print PDF documents or save rendered pages as image files. IronPDF supports both operations through its comprehensive API. Using this feature doesn't compromise system security or require complex math to calculate print margins.

Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
    If currentPdf IsNot Nothing Then
        Dim printDialog As New PrintDialog()
        If printDialog.ShowDialog() = DialogResult.OK Then
            currentPdf.Print()
        End If
    End If
End Sub

Private Sub btnSaveImage_Click(sender As Object, e As EventArgs) Handles btnSave.Click
    If PictureBox1.Image IsNot Nothing Then
        Using saveDialog As New SaveFileDialog()
            saveDialog.Filter = "PNG Image|*.png|JPEG Image|*.jpg|TIF Image|*.tif"
            If saveDialog.ShowDialog() = DialogResult.OK Then
                PictureBox1.Image.Save(saveDialog.FileName)
            End If
        End Using
    End If
End Sub
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
    If currentPdf IsNot Nothing Then
        Dim printDialog As New PrintDialog()
        If printDialog.ShowDialog() = DialogResult.OK Then
            currentPdf.Print()
        End If
    End If
End Sub

Private Sub btnSaveImage_Click(sender As Object, e As EventArgs) Handles btnSave.Click
    If PictureBox1.Image IsNot Nothing Then
        Using saveDialog As New SaveFileDialog()
            saveDialog.Filter = "PNG Image|*.png|JPEG Image|*.jpg|TIF Image|*.tif"
            If saveDialog.ShowDialog() = DialogResult.OK Then
                PictureBox1.Image.Save(saveDialog.FileName)
            End If
        End Using
    End If
End Sub
VB .NET

Print Dialog

VB .NET Display PDF in PictureBox: Render PDF Pages as Images in Windows Forms: Image 5 - Example of print button working

The print functionality uses IronPDF's built-in Print method which integrates with Microsoft Windows print infrastructure. The save feature exports the current page as an image file in the user's choice of formats. These features make the PDF viewer suitable for document management applications.

Conclusion

Building a PDF viewer in VB.NET Windows Forms applications becomes straightforward with IronPDF's image conversion capabilities. By rendering PDF pages as bitmaps, developers can display PDF documents in standard PictureBox controls without external dependencies. The approach supports page navigation, zoom control, and print functionality for complete document viewing solutions.

Start your free trial to implement PDF display in your Windows Forms projects, or purchase a license for production deployment.

Frequently Asked Questions

How can I display a PDF in a Windows Forms PictureBox using VB.NET?

You can display a PDF in a Windows Forms PictureBox by using IronPDF's ToBitmap method, which allows you to render PDF pages as images.

What method does IronPDF provide for rendering PDF pages in VB.NET?

IronPDF provides the ToBitmap method for rendering PDF pages as images, which can then be displayed in a PictureBox control in VB.NET.

Is it possible to navigate PDF pages in a PictureBox?

Yes, you can navigate PDF pages by using IronPDF's page navigation features, allowing you to display different pages in a PictureBox control.

What are the advantages of using IronPDF for displaying PDFs in Windows Forms?

IronPDF simplifies the process of displaying PDFs in Windows Forms by converting PDF pages to images, which can be easily integrated into controls like PictureBox. It also supports features like page navigation.

Can IronPDF handle multi-page PDFs for display in PictureBox?

Yes, IronPDF can handle multi-page PDFs. You can use its methods to select and render specific pages as images for display in a PictureBox.

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