How to View PDF Files in VB.NET

The Portable Document Format (PDF) has become a widely used format for sharing and viewing documents across various platforms and devices. To offer a seamless viewing experience for PDF files within a VB .NET application, IronPDF provides a robust PDF viewer component. In this article, we will delve into creating a PDF viewer in VB.NET using IronPDF. We will cover multiple aspects, including PDF document creation, parsing and manipulation of existing PDF files, the addition of images to PDFs, and integration of a PDF viewer into a VB.NET application without the need for Adobe PDF Reader.

How to View PDF Files in VB.NET: Figure 1 - IronPDF

1. Overview of IronPDF and VB.NET PDF Viewer

IronPDF is a powerful .NET library that provides comprehensive functionality for working with PDF files in VB.NET applications. It offers a range of features, including PDF creation, parsing, manipulation, and viewing. The PDF viewer component provided by IronPDF allows developers to seamlessly integrate a PDF viewer into their VB.NET applications, enabling users to view PDF documents without relying on external tools such as Adobe PDF Reader.

2. Creating PDF files

IronPDF simplifies the process of creating PDF documents in VB.NET. There are multiple approaches you can take to generate PDFs using IronPDF. Here are some examples:

Using HTML to Create a PDF File

IronPDF allows you to convert HTML content to PDF. By leveraging the HTML to PDF conversion capability, you can easily generate PDF documents from HTML templates or dynamically generated HTML content. The IronPDF website provides sample code and examples of how to accomplish this.

Imports IronPdf

' Instantiate Renderer
Private renderer = New ChromePdfRenderer()

' Create a PDF from a HTML string using C#
Private pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")

' Export to a file or Stream
pdf.SaveAs("output.pdf")

' Advanced Example with HTML Assets
' Load external html assets: Images, CSS and JavaScript.
' An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
Dim myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")
myAdvancedPdf.SaveAs("html-with-assets.pdf")
Imports IronPdf

' Instantiate Renderer
Private renderer = New ChromePdfRenderer()

' Create a PDF from a HTML string using C#
Private pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")

' Export to a file or Stream
pdf.SaveAs("output.pdf")

' Advanced Example with HTML Assets
' Load external html assets: Images, CSS and JavaScript.
' An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
Dim myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")
myAdvancedPdf.SaveAs("html-with-assets.pdf")
VB.NET

Converting XML to PDF

If you have XML data that needs to be converted into a PDF document, IronPDF simplifies the process. It provides methods to convert XML data to PDF, allowing you to customize the styling and layout of the resulting PDF.

string xslt = @"<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='/'>
<html>
<style>
td{
  text-align: center;
  padding: 20px;
  border: 1px solid #CDE7F0;
}
th{
  color: white;
  padding: 20px;
}
</style>
<body style='font-family: Arial, Helvetica Neue, Helvetica, sans-serif;'>
  <table style='border-collapse: collapse;'>
  <thead>
    <tr>
      <th colspan='3'>
        <img style='margin: auto;' src='https://ironsoftware.com/img/svgs/ironsoftware-logo-black.svg'/>
      </th>
    </tr>
  </thead>
  <tbody>
    <tr bgcolor='#9acd32'>
      <th bgcolor='#32ab90'>Title</th>
      <th bgcolor='#f49400'>Feature</th>
      <th bgcolor='#2a95d5'>Compatible</th>
    </tr>
    <xsl:for-each select='catalog/cd'>
    <tr>
      <td style='font-weight: bold;'><xsl:value-of select='title'/></td>
      <td style='background-color: #eff8fb; color: #2a95d5; font-weight: bold;'><xsl:value-of select='feature'/></td>
      <td><xsl:value-of select='compatible'/></td>
    </tr>
    </xsl:for-each>
    </tbody>
  </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
";
string xml = @"<?xml version='1.0' encoding='UTF-8'?>
<catalog>
  <cd>
    <title>IronPDF</title>
    <feature>Generate, format and manipulate PDFs</feature>
    <compatible>Microsoft Windows, Linux (Debian, CentOS, Ubuntu), MacOS, Docker (Windows, Linux, Azure), Azure (VPS, Webapps, Websites, Functions), AWS</compatible>
  </cd>
  <cd>
    <title>IronOCR</title>
    <feature>OCR engine, input, result</feature>
    <compatible>Microsoft Windows, Linux, MacOS, Docker, Azure, AWS</compatible>
  </cd>
  <cd>
    <title>IronBarcode</title>
    <feature>Format, read and write Barcode</feature>
    <compatible>Microsoft Windows, Linux, MacOS, Docker, Azure, AWS</compatible>
  </cd>
</catalog>
";
XslCompiledTransform transform = new XslCompiledTransform();
using (XmlReader reader = XmlReader.Create(new StringReader(xslt)))
{
    transform.Load(reader);
}
StringWriter results = new StringWriter();
using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
{
    transform.Transform(reader, null, results);
}
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
// options, headers and footers may be set there
// Render our XML as a PDF via XSLT
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf");
string xslt = @"<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='/'>
<html>
<style>
td{
  text-align: center;
  padding: 20px;
  border: 1px solid #CDE7F0;
}
th{
  color: white;
  padding: 20px;
}
</style>
<body style='font-family: Arial, Helvetica Neue, Helvetica, sans-serif;'>
  <table style='border-collapse: collapse;'>
  <thead>
    <tr>
      <th colspan='3'>
        <img style='margin: auto;' src='https://ironsoftware.com/img/svgs/ironsoftware-logo-black.svg'/>
      </th>
    </tr>
  </thead>
  <tbody>
    <tr bgcolor='#9acd32'>
      <th bgcolor='#32ab90'>Title</th>
      <th bgcolor='#f49400'>Feature</th>
      <th bgcolor='#2a95d5'>Compatible</th>
    </tr>
    <xsl:for-each select='catalog/cd'>
    <tr>
      <td style='font-weight: bold;'><xsl:value-of select='title'/></td>
      <td style='background-color: #eff8fb; color: #2a95d5; font-weight: bold;'><xsl:value-of select='feature'/></td>
      <td><xsl:value-of select='compatible'/></td>
    </tr>
    </xsl:for-each>
    </tbody>
  </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
";
string xml = @"<?xml version='1.0' encoding='UTF-8'?>
<catalog>
  <cd>
    <title>IronPDF</title>
    <feature>Generate, format and manipulate PDFs</feature>
    <compatible>Microsoft Windows, Linux (Debian, CentOS, Ubuntu), MacOS, Docker (Windows, Linux, Azure), Azure (VPS, Webapps, Websites, Functions), AWS</compatible>
  </cd>
  <cd>
    <title>IronOCR</title>
    <feature>OCR engine, input, result</feature>
    <compatible>Microsoft Windows, Linux, MacOS, Docker, Azure, AWS</compatible>
  </cd>
  <cd>
    <title>IronBarcode</title>
    <feature>Format, read and write Barcode</feature>
    <compatible>Microsoft Windows, Linux, MacOS, Docker, Azure, AWS</compatible>
  </cd>
</catalog>
";
XslCompiledTransform transform = new XslCompiledTransform();
using (XmlReader reader = XmlReader.Create(new StringReader(xslt)))
{
    transform.Load(reader);
}
StringWriter results = new StringWriter();
using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
{
    transform.Transform(reader, null, results);
}
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
// options, headers and footers may be set there
// Render our XML as a PDF via XSLT
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf");
Dim xslt As String = "<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match='/'>
<html>
<style>
td{
  text-align: center;
  padding: 20px;
  border: 1px solid #CDE7F0;
}
th{
  color: white;
  padding: 20px;
}
</style>
<body style='font-family: Arial, Helvetica Neue, Helvetica, sans-serif;'>
  <table style='border-collapse: collapse;'>
  <thead>
    <tr>
      <th colspan='3'>
        <img style='margin: auto;' src='https://ironsoftware.com/img/svgs/ironsoftware-logo-black.svg'/>
      </th>
    </tr>
  </thead>
  <tbody>
    <tr bgcolor='#9acd32'>
      <th bgcolor='#32ab90'>Title</th>
      <th bgcolor='#f49400'>Feature</th>
      <th bgcolor='#2a95d5'>Compatible</th>
    </tr>
    <xsl:for-each select='catalog/cd'>
    <tr>
      <td style='font-weight: bold;'><xsl:value-of select='title'/></td>
      <td style='background-color: #eff8fb; color: #2a95d5; font-weight: bold;'><xsl:value-of select='feature'/></td>
      <td><xsl:value-of select='compatible'/></td>
    </tr>
    </xsl:for-each>
    </tbody>
  </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
"
Dim xml As String = "<?xml version='1.0' encoding='UTF-8'?>
<catalog>
  <cd>
    <title>IronPDF</title>
    <feature>Generate, format and manipulate PDFs</feature>
    <compatible>Microsoft Windows, Linux (Debian, CentOS, Ubuntu), MacOS, Docker (Windows, Linux, Azure), Azure (VPS, Webapps, Websites, Functions), AWS</compatible>
  </cd>
  <cd>
    <title>IronOCR</title>
    <feature>OCR engine, input, result</feature>
    <compatible>Microsoft Windows, Linux, MacOS, Docker, Azure, AWS</compatible>
  </cd>
  <cd>
    <title>IronBarcode</title>
    <feature>Format, read and write Barcode</feature>
    <compatible>Microsoft Windows, Linux, MacOS, Docker, Azure, AWS</compatible>
  </cd>
</catalog>
"
Dim transform As New XslCompiledTransform()
Using reader As XmlReader = XmlReader.Create(New StringReader(xslt))
	transform.Load(reader)
End Using
Dim results As New StringWriter()
Using reader As XmlReader = XmlReader.Create(New StringReader(xml))
	transform.Transform(reader, Nothing, results)
End Using
Dim Renderer As New IronPdf.ChromePdfRenderer()
' options, headers and footers may be set there
' Render our XML as a PDF via XSLT
Renderer.RenderHtmlAsPdf(results.ToString()).SaveAs("Final.pdf")
VB   C#

How to View PDF Files in VB.NET: Figure 2 - XML to PDF

Adding Images to PDFs

IronPDF enables you to add images to PDF documents. You can specify the position, size, and other properties of the image within the PDF. This can be useful when creating reports or documents that require visual elements.

Dim lstimages As List(Of String) = New List(Of String) 
lstimages.Add("test.png") lstimages.Add("demo.png") 
Dim pdfdoc = ImageToPdfConverter.ImageToPdf(lstimages).SaveAs("Resultimage.pdf")  
Dim lstimages As List(Of String) = New List(Of String) 
lstimages.Add("test.png") lstimages.Add("demo.png") 
Dim pdfdoc = ImageToPdfConverter.ImageToPdf(lstimages).SaveAs("Resultimage.pdf")  
VB.NET

How to View PDF Files in VB.NET: Figure 3 - How to Parse PDF File in VB.NET: Figure 4 - Extract Image from PDF output

3. Parsing and Manipulating PDF Files

IronPDF also provides capabilities for parsing and manipulating existing PDF files. You can extract text, images, and other elements from PDF documents, modify their properties, merge multiple PDFs into a single document, split a PDF into multiple files, and perform various other operations. Here's an example of how you can parse a PDF file using IronPDF in VB.NET:

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

IronPDF provides a comprehensive set of APIs and methods to manipulate PDF files, making it a versatile tool for working with PDF documents in your VB.NET applications.

How to View PDF Files in VB.NET: Figure 4 - How to Parse PDF File in VB.NET: Figure 3 - Extract text between pages output

4. Integrating a PDF Viewer into a VB.NET Application

Now, let's explore how to integrate a PDF viewer into a VB.NET application using IronPDF. We'll cover the necessary steps, including setting up the project, adding the PDFViewer control, loading and displaying PDF documents, implementing PDF window options, and printing PDF documents.

Setting Up the Project

To begin, create a new VB.NET Windows Forms Application project in Visual Studio. Make sure you have the IronPDF library added as a reference to your project.

Loading and Displaying PDF Documents

To load and display a PDF document in the VB.NET, you need to provide the file path or stream of the PDF document. Here's an example:

Dim Renderer As var = New IronPdf.HtmlToPdf
Dim PDFs As var = New List(Of PdfDocument)
PDFs.Add(PdfDocument.FromFile("A.pdf"))
PDF.PrependPdf(Renderer.RenderHtmlAsPdf("<h1>Cover Page</h1><hr>"))
PDF.SaveAs("CoverAdded.pdf")
PDF.Dispose();
Dim Renderer As var = New IronPdf.HtmlToPdf
Dim PDFs As var = New List(Of PdfDocument)
PDFs.Add(PdfDocument.FromFile("A.pdf"))
PDF.PrependPdf(Renderer.RenderHtmlAsPdf("<h1>Cover Page</h1><hr>"))
PDF.SaveAs("CoverAdded.pdf")
PDF.Dispose();
VB.NET

Printing PDF Documents

IronPDF provides a convenient way to print PDF documents directly from your VB.NET application in the Print method of the PDFViewer control. Here's an example:

Dim document = New ChromePdfRenderer()
'Create new PdfDocument PDF and render URL into PDF document
        Dim PDF As PdfDocument = document.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
  PDF.SaveAs("UrlToPdf.pdf")
'Print PDF in 300 DPI without user new printdialog
        PDF.Print(300, False)
'For advance printing, you can use below 
        Dim PrintDocYouCanWorkWith As PrintDocument = PDF.GetPrintDocument()   
Dim document = New ChromePdfRenderer()
'Create new PdfDocument PDF and render URL into PDF document
        Dim PDF As PdfDocument = document.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
  PDF.SaveAs("UrlToPdf.pdf")
'Print PDF in 300 DPI without user new printdialog
        PDF.Print(300, False)
'For advance printing, you can use below 
        Dim PrintDocYouCanWorkWith As PrintDocument = PDF.GetPrintDocument()   
VB.NET

By calling the GetPrintDocument method, you can initiate the printing process for the currently loaded PDF document.

5. Conclusion

In this article, we explored how to create a PDF viewer in VB.NET using IronPDF. We covered various aspects, including creating PDF documents using IronPDF's HTML-to-PDF conversion, XML-to-PDF conversion, and image insertion capabilities. We also delved into parsing and manipulating existing PDF files using IronPDF. Finally, we discussed the process of integrating the PDFViewer control into a VB.NET application, loading and displaying PDF documents, implementing PDF window options, and printing PDFs.

By leveraging IronPDF's powerful features, you can enhance your VB.NET applications by providing seamless PDF viewing functionality. Whether you need to create PDF documents, parse and manipulate existing PDFs or integrate a PDF viewer, IronPDF offers a comprehensive solution.

Remember to refer to the IronPDF documentation and the provided sample codes for further details and customization options. With IronPDF's capabilities, you can empower your VB.NET applications to handle PDF files efficiently, offering a seamless and feature-rich experience to your users.

As you explore the various features and possibilities offered by IronPDF, you will have the flexibility to create, manipulate, and view PDF documents effortlessly within your VB.NET applications. Harness the power of IronPDF and unlock new possibilities for working with PDF files in your projects.

Now that you have a solid understanding of creating a PDF viewer in VB.NET using IronPDF, you can embark on your journey to integrate this powerful functionality into your own applications. Enjoy the benefits of a versatile PDF viewer component and empower your users to view PDF documents without relying on external tools. With IronPDF's extensive capabilities, you can streamline your document management processes and provide a seamless viewing experience.

Feel free to experiment, explore, and refer to the IronPDF documentation and code samples to gain a deeper understanding of the library's capabilities. With IronPDF by your side, you can confidently conquer PDF manipulation and viewing in your VB.NET applications.

Learn how to use PDF viewer in MAUI by visiting "Viewing PDFs in MAUI" tutorial.