USING IRONPRINT

How to Print PDF in VB.NET (Step-by-Step) Tutorial

Updated January 29, 2023
Share:

This article describes the process of how to print URL pages with images as PDF pages/documents at runtime system in ASP.NET Web Application using VB.NET. The article will use the IronPDF library for printing PDF documents through URLs in the ASP.NET Web Application with Web/Windows Forms or pages using the default printer.

About the IronPDF library

IronPDF is a C# and VB.NET PDF library that allows you to print URLs as PDF files/documents without using Adobe Acrobat Reader and the default printer. This product offers a new system solution for developers who wish to print URL content into a PDF file/pages and then print PDF with print preview notes. IronPDF can be used with ASP.NET Web Applications or Windows Forms to generate PDF documents and print PDF files in a way that HTML pages are built without using the default printer. It allows programmers the ability to create PDF files and documents from scratch in ASP.NET Web Applications without having any prior knowledge of Adobe Acrobat or other third-party application tools. Let's see how we can use it in the ASP.NET Web Application for PDF printing/drawing through URL. You can also use Windows Forms in the .NET application for converting URLs into PDF documents and then printing PDF documents using a printer.

It also allows developers to generate, edit, extract, and print PDF document content within .NET Core and Framework projects as .NET applications. Using the IronPDF library, we can print a URL as a PDF document.

Create an ASP.NET Web Application for Generating PDF Files

Follow the following steps for creating an ASP.NET Web Application.

  • Open Visual Studio and click the "Create New Project" button.
  • From the template list, select ASP.NET Web Application.
  • Give a proper name to your application.
  • Select a .NET Framework and click on the 'Create' button.

Learn how to work with IronPDF using VB.NET by reading this tutorial.

Installing the IronPDF library

There are multiple ways to install the IronPDF library.

  • Using NuGet Command Line
  • Using NuGet GUI
  • Download from NuGet Website

The easiest way to install IronPDF is using the NuGet Command Line. Go to the NuGet Command Line, write the following statement, and press the Enter button.

Install-Package IronPrint

IronPDF installation will start. After installation, you will be able to use the IronPDF file in your project. For confirmation that the IronPDF file has been installed, expand the Dependencies section in Solution Explorer and click on the Packages section. You will see the IronPDF file package there.

Now, this project is ready to use IronPDF. Let's see how to use it in the ASP.NET Web Application with Web Forms.

Using IronPDF in ASP.NET Web Application with Web Forms

Add a button for printing PDF files. For example, write the following code snippet on the Default.aspx page for that purpose which is the default filename and first page or web form of the application. Check the below sample code.

<div>       
    <asp:Button ID="Button1" runat="server" Text="Generate PDF" OnClick="Button1_Click" /> 
</div>
<div>       
    <asp:Button ID="Button1" runat="server" Text="Generate PDF" OnClick="Button1_Click" /> 
</div>
HTML

First, in the above code, a div is added with an asp:Button (server control) in it. The text on the button has been set to read "Generate PDF." There is also an OnClick event defined on the button.

Print Web Page Content as PDF

Now, it's time to write a post-action to generate a PDF file. After adding an OnClick event in Default.aspx page, it automatically added an event Button1_Click in Default.aspx.cs file.

Include the following import statements at the top of the Default.aspx.cs source file:

Imports IronPdf
Imports System.Drawing.Printing
Imports IronPdf
Imports System.Drawing.Printing
VB.NET

Enter the following code snippet in the source file for the Button1_Click event:

Public Class _Default
Inherits Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs)

'Creating an object named document of ChromePdfRenderer class
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()
End Sub
End Class
Public Class _Default
Inherits Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs)

'Creating an object named document of ChromePdfRenderer class
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()
End Sub
End Class
VB.NET

Firstly, create an instance of the ChromePdfRenderer class. After that, use the RenderUrlAsPdf function to convert a URL to PDF pages. In the method parameter, provide the URL of the web page that is needed to convert. In this case, provide the URL as "https://www.nuget.org/packages/IronPdf". After generating the PDF, save it to the computer using the SaveAs function. Afterward, call the Print method with a specified DPI to print the document. The third False parameter value makes it print without displaying the Print Dialog box.

Run the project. You will see the welcome page with a "Generate PDF" button.

When you click on the "Generate PDF" button, it will print a PDF document via the default selected printer.

You will see the hard copy of content that has been generated by the IronPDF. The content in the hard copy is the same as mentioned in the URL and printed PDF documents.

Conclusion

IronPDF is a great tool for .NET developers to manipulate and print PDFs in their .NET projects without using Adobe Reader. It provides features in multiple languages like C# and VB.NET which are handy for developers to pace up their work. You can format PDF files, delete or add pages, add PNG or graphics in PDF and many more. IronPDF is free for development.

IronPDF offers developers methods to render PDF documents into images and extract text and content from a PDF. IronPDF also can merge and split PDF files, edit PDF forms, and enhance security with passwords.

< PREVIOUS
C# Send PDF to Printer (Step-By-Step Tutorial)
NEXT >
C# Print PDF to Specific Printer (Code Example Tutorial)

Ready to get started? Version: 2024.5 just released

Start Free Trial Total downloads: 3,233
View Licenses >