VB.NET PDF Creator (Code Example Tutorial)

This tutorial will guide you step-by-step on how to create and edit PDF files in VB.NET. This technique is equally valid for use in ASP.NET web apps as well as console applications, Windows Services, and desktop programs. We will use VB.NET to create PDF projects targeting .NET Framework 4.6.2 or .NET Core 2. All you need is a Visual Basic .NET development environment, such as Microsoft Visual Studio Community.

To see how to use IronPDF with C# see this guide.

To see how to use IronPDF with F# see this guide.


Overview

How to Generate PDF Files in VB .NET Library

  1. Download the VB.NET PDF Library
  2. Create a PDF document with VB.NET Library
  3. Customize your PDF document styles
  4. Choose which methods to create dynamic content
  5. Edit your PDF files from VB.NET Library

VB .NET Codes for PDF Creating and Editing with IronPDF

Render HTML to PDF with VB.NET, apply styling, utilize dynamic content, and edit your files easily. Creating PDFs is straightforward and compatible with .NET Framework 4.6.2, .NET Core 3.1, .NET 8, 7, 6 & 5. And no need for proprietary file formats or dealing with different APIs.

This tutorial provides the documentation to walk you through each task step-by-step, all using the free-for-development IronPDF software favored by developers. VB.NET code examples are specific to your use cases so you can see the steps easily in a familiar environment. This VB .NET PDF library has comprehensive creation and settings capabilities for every project, whether in ASP.NET applications, console, or desktop.

Included with IronPDF:

  • Ticket support direct from our .NET PDF Library development team
  • Works with HTML, ASPX forms, MVC views, images, and all the document formats you already use
  • Microsoft Visual Studio installation gets you up and running fast
  • Unlimited free development, and licenses to go live starting at $749

Step 1

1. Download the VB .NET PDF Library FREE from IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer

Install via NuGet

In Visual Studio, right-click on your project in the Solution Explorer and select "Manage NuGet Packages...". From there simply search for IronPDF and install the latest version... click OK to any dialog boxes that come up.

This will work in any C# .NET Framework project from Framework 4.6.2 and above, or .NET Core 2 and above. It will also work just as well in VB.NET projects.

Install-Package IronPdf

Download IronPDF from NuGet

Install via DLL

Alternatively, the IronPDF DLL can be downloaded and manually installed to the project or GAC from IronPDF Downloads

Remember to add this statement to the top of any VB class file using IronPDF:

Imports IronPdf

How to Tutorials

2. Create a PDF with VB.NET

Using Visual Basic ASP.NET to create a PDF file for the first time is surprisingly easy using IronPDF, as compared to libraries with proprietary design APIs such as iTextSharp.

We can use HTML (with a pixel-perfect rendering engine based on Google Chromium) to define the content of our PDF and simply render it to a file.

Here is the basic code to create a PDF in VB.NET:

:path=/static-assets/pdf/content-code-examples/how-to/vb-net-pdf-1.cs

This will produce a .NET-generated PDF file containing your exact text, albeit lacking some design at this point.

To improve upon this code, we can add the following line to open the PDF in the operating system's default PDF viewer:

:path=/static-assets/pdf/content-code-examples/how-to/vb-net-pdf-2.cs

An alternative method would be to render any existing web page from a URL to a PDF by using the elegant RenderUrlAsPdf method from IronPDF.

:path=/static-assets/pdf/content-code-examples/how-to/vb-net-pdf-3.cs
PDF.SaveAs("webpage.pdf")

3. Apply Styling to VB.NET PDF

To style our PDF content in VB.NET, we can make full use of CSS, JavaScript, and images. We may link to local assets, or even to remote or CDN-based assets such as Google Fonts. We can even use DataURIs to embed images and assets as a string into your HTML.

For advanced design, we can use a 2-stage process:

  1. First, we develop and design our HTML perfectly. This task may involve in-house design staff, splitting the workload.
  2. Render that file as a PDF using VB.NET and our PDF library.

The VB.NET Code to render the HTML file as a PDF:

This method renders an HTML document as if it were opened as a file (file:// protocol).

Dim Renderer As New IronPdf.ChromePdfRenderer()
Renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape 
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print 
Dim PDF As IronPdf.PdfDocument = Renderer.RenderUrlAsPdf("file://path-to-your-html-file.html")
PDF.SaveAs("styled-sample.pdf")

4. Create PDF w/ Dynamic Content: 2 Methods

Historically, PDF 'templating' has been an overwhelming task for Software Engineers. Stamping content into PDF templates rarely works because each case or report will contain content of varying types and lengths. Fortunately, HTML is exceptionally good at handling Dynamic Data.

4.1. Method 1 - ASP.NET - ASPX to PDF using VB.NET Web Forms

Any flavor of .NET Web Form (including Razor) can be rendered into a PDF document using this VB.NET code in the Page_Load subroutine in the VB.NET code behind.

:path=/static-assets/pdf/content-code-examples/how-to/vb-net-pdf-8.cs

4.2. Method 2 - HTML to PDF with String Templating

To create dynamic PDF documents that include instance-specific data, we simply create an HTML string to match the data we wish to render as a PDF.

:path=/static-assets/pdf/content-code-examples/how-to/vb-net-pdf-9.cs

5. Edit PDF Files with VB.NET

IronPDF for VB.NET also allows PDF documents to be edited, encrypted, watermarked, or even turned back into plain text:

5.1. Merging Multiple PDF Files into One Document in VB

:path=/static-assets/pdf/content-code-examples/how-to/vb-net-pdf-10.cs

5.2. Add a Cover Page to the PDF

:path=/static-assets/pdf/content-code-examples/how-to/vb-net-pdf-11.cs

5.3. Remove the last page from the PDF

:path=/static-assets/pdf/content-code-examples/how-to/vb-net-pdf-12.cs

5.4. Encrypt a PDF using 128 Bit Encryption

:path=/static-assets/pdf/content-code-examples/how-to/vb-net-pdf-13.cs

5.5. Stamp Additional HTML Content Onto a Page in VB

:path=/static-assets/pdf/content-code-examples/how-to/vb-net-pdf-14.cs

5.6. Add Page Break to PDF Using HTML

The easiest way to do this is with HTML and CSS:

:path=/static-assets/pdf/content-code-examples/how-to/vb-net-pdf-15.cs
<div style='page-break-after: always;'>&nbsp;</div>
HTML

6. More .NET PDF Tutorials

You may also be interested in:


Conclusion

In this tutorial, we discovered 6 ways to achieve VB.NET to PDF results using VB.NET as our programming language of choice.

  • HTML string to PDF
  • Creating a PDF in VB.NET using an HTML string to define its content
  • Rendering existing URLs as PDF files
  • Generating PDF from HTML files
  • HTML templating in VB.NET and conversion to dynamic PDFs
  • Converting ASP.NET pages with live data, such as ASPX to PDF files

For each, we used the popular IronPDF VB.NET library to allow us to turn HTML directly into PDF documents within .NET projects.


Tutorial Quick Access

Brand Visual Studio related to Tutorial Quick Access

Download this Tutorial as Source Code

The full free VB.NET HTML to PDF Source Code for this tutorial is available to download as a zipped Visual Studio project file.

Download

Explore this Tutorial on GitHub

You may also be interested in our extensive library of VB.NET PDF generation and manipulation examples on GitHub. Exploring source code is the fastest way to learn, and Github is the definitive way to do so online. I hope these examples help you get to grips with PDF related functionality in your VB projects.

Creating PDFS in ASP.NET with VB.NET and C# Source A Simple Hello World Project to Render HTML to PDF in VB.NET using IronPDF Exploring HTML To PDF in-depth with VB.NET
Github Icon related to Tutorial Quick Access
Html To Pdf Icon related to Tutorial Quick Access

Download C# PDF Quickstart guide

To make developing PDFs in your .NET applications easier, we have compiled a quick-start guide as a PDF document. This "Cheat-Sheet" provides quick access to common functions and examples for generating and editing PDFs in C# and VB.NET - and will save time getting started using IronPDF in your .NET project.

Download

View the API Reference

Explore the API Reference for IronPDF, outlining the details of all of IronPDF’s features, namespaces, classes, methods fields and enums.

View the API Reference
Documentation related to Tutorial Quick Access

Frequently Asked Questions

How do I install the VB.NET PDF Library?

You can install the VB.NET PDF Library from IronPDF via NuGet by right-clicking on your project in Visual Studio's Solution Explorer, selecting 'Manage NuGet Packages...', searching for IronPDF, and installing the latest version. Alternatively, you can download the IronPDF DLL and manually install it to your project or GAC.

How can I create a PDF using VB.NET?

You can create a PDF using VB.NET by using IronPDF's ChromePdfRenderer class. For example, you can render HTML to PDF with the following code: Dim Renderer As New IronPdf.ChromePdfRenderer(), Dim PDF As IronPdf.PdfDocument = Renderer.RenderHtmlAsPdf('

Hello World!

'), PDF.SaveAs('sample.pdf').

What methods are available for creating dynamic content in a PDF?

There are two primary methods for creating dynamic content in PDFs using VB.NET: Method 1 involves using ASP.NET Web Forms to render dynamic content into a PDF, and Method 2 involves using HTML to PDF conversion with string templating to include instance-specific data.

How can I edit a PDF file using VB.NET?

Using IronPDF, PDF files can be edited in several ways including merging multiple PDFs, adding a cover page, removing pages, encrypting PDFs, and stamping additional content onto pages. For example, to merge PDFs, use IronPdf.PdfDocument.Merge method.

Can I apply styling to PDF content in VB.NET?

Yes, you can apply styling to PDF content in VB.NET using CSS, JavaScript, and images. This can include linking to local or remote assets and using DataURIs to embed images directly into the HTML.

Is it possible to render a web page directly as a PDF in VB.NET?

Yes, using IronPDF's RenderUrlAsPdf method, you can render any existing web page directly as a PDF. This allows you to convert the entire web page, including its content and styling, into a PDF file.

What are the system requirements for using the PDF library with VB.NET?

IronPDF is compatible with .NET Framework 4.6.2 and above, as well as .NET Core 2 and above. It works seamlessly with VB.NET projects in these environments.

Is there support available for the VB.NET PDF library?

Yes, IronPDF offers ticket support directly from their .NET PDF Library development team, ensuring you have access to help when needed.

Can I view the API Reference for the PDF library?

Yes, you can view the API Reference for IronPDF, which outlines all of its features, namespaces, classes, methods, fields, and enums, on the IronPDF website.

Where can I find more tutorials on using the VB.NET PDF library?

You can find more tutorials on the IronPDF website as well as their GitHub repository. These resources provide additional examples and use cases for creating and manipulating PDFs with VB.NET.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.
Reviewed by
Jeff Fritz
Jeffrey T. Fritz
Principal Program Manager - .NET Community Team
Jeff is also a Principal Program Manager for the .NET and Visual Studio teams. He is the executive producer of the .NET Conf virtual conference series and hosts 'Fritz and Friends' a live stream for developers that airs twice weekly where he talks tech and writes code together with viewers. Jeff writes workshops, presentations, and plans content for the largest Microsoft developer events including Microsoft Build, Microsoft Ignite, .NET Conf, and the Microsoft MVP Summit