Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
This article will delve into creating a PDF viewer in VB.NET using IronPDF. It will cover multiple aspects, including the creation of PDF documents, parsing and manipulation of existing PDF files, and addition of images to PDFs.
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.
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:
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")
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")
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")
Extract images from a PDF file
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
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.
Extract text between pages output
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.
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.
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.ChromePdfRenderer
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.ChromePdfRenderer
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();
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 renderer = New ChromePdfRenderer()
'Create new PdfDocument PDF and render URL into PDF document
Dim PDF As PdfDocument = renderer.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 renderer = New ChromePdfRenderer()
'Create new PdfDocument PDF and render URL into PDF document
Dim PDF As PdfDocument = renderer.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()
By calling the GetPrintDocument
method, you can initiate the printing process for the currently loaded PDF document.
This article explored how to create a PDF viewer in VB.NET using IronPDF. Covered various aspects, including creating PDF documents using IronPDF's HTML-to-PDF conversion, XML-to-PDF conversion, and image insertion capabilities, and parsing and manipulating existing PDF files using IronPDF. Finally, integrating the PDFViewer
control into a VB.NET application, loading and displaying PDF documents, implementing PDF window options, and printing PDFs.
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. Additionally, IronPDF is also capable of rendering charts in PDFs, adding barcodes, enhancing security with passwords and watermarking, and even handling PDF forms programmatically.
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.
9 .NET API products for your office documents