Skip to footer content
USING IRONPRINT

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

<div class="alert alert-info iron-variant-1" role="alert">
<a href="https://ironsoftware.com/csharp/print/">IronPrint</a> is Iron Software's brand new .NET printing library, offering compatibility across a wide range of platforms, including Windows, macOS, Android, and iOS. <a href="https://ironsoftware.com/csharp/print/docs/">Get started with IronPrint</a> now!
</div>
<div class="alert alert-info iron-variant-1" role="alert">
<a href="https://ironsoftware.com/csharp/print/">IronPrint</a> is Iron Software's brand new .NET printing library, offering compatibility across a wide range of platforms, including Windows, macOS, Android, and iOS. <a href="https://ironsoftware.com/csharp/print/docs/">Get started with IronPrint</a> now!
</div>
HTML

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.

<div class="hsg-featured-snippet">
    <h2>How to Print PDF File in VB.NET</h2>
    <ol>
        <li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronPdf/">Install VB library to print PDF files</a></li>
        <li>Create ASP.NET Web Application</li>
        <li>Use <code>RenderUrlAsPdf</code> method in VB to render website into PDF</li>
        <li>Perform print action to the default printer with <code>Print</code> method</li>
        <li>Execute <code>SaveAs</code> method to save the PDF as a new document</li>
    </ol>
</div>
<div class="hsg-featured-snippet">
    <h2>How to Print PDF File in VB.NET</h2>
    <ol>
        <li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://nuget.org/packages/IronPdf/">Install VB library to print PDF files</a></li>
        <li>Create ASP.NET Web Application</li>
        <li>Use <code>RenderUrlAsPdf</code> method in VB to render website into PDF</li>
        <li>Perform print action to the default printer with <code>Print</code> method</li>
        <li>Execute <code>SaveAs</code> method to save the PDF as a new document</li>
    </ol>
</div>
HTML

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 the 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
        ' This method is executed on each page load
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs)
        ' Creating an instance of ChromePdfRenderer to convert web page content to PDF
        Dim document = New ChromePdfRenderer()

        ' Create new PdfDocument by rendering a specified URL
        Dim PDF As PdfDocument = document.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")

        ' Save the PDF document to a file named "UrlToPdf.pdf"
        PDF.SaveAs("UrlToPdf.pdf")

        ' Print the PDF document at 300 DPI without showing the print dialog
        PDF.Print(300, False)

        ' For more advanced printing, you can modify PrintDocument settings
        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
        ' This method is executed on each page load
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs)
        ' Creating an instance of ChromePdfRenderer to convert web page content to PDF
        Dim document = New ChromePdfRenderer()

        ' Create new PdfDocument by rendering a specified URL
        Dim PDF As PdfDocument = document.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")

        ' Save the PDF document to a file named "UrlToPdf.pdf"
        PDF.SaveAs("UrlToPdf.pdf")

        ' Print the PDF document at 300 DPI without showing the print dialog
        PDF.Print(300, False)

        ' For more advanced printing, you can modify PrintDocument settings
        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.

Frequently Asked Questions

How can I print a web page as a PDF using VB.NET?

You can use IronPDF's RenderUrlAsPdf method to convert a web page URL into a PDF document in VB.NET. After rendering, use the Print method to print the document without displaying a print dialog.

What is the process to install the PDF library for VB.NET projects?

To install IronPDF for VB.NET projects, use the NuGet Package Manager in Visual Studio. You can install it by searching for 'IronPDF' in the NuGet Package Manager GUI or using the NuGet Command Line.

What are the benefits of using IronPDF for PDF generation in VB.NET?

IronPDF allows developers to generate high-quality PDFs from web pages, edit and extract PDF content, and incorporate graphics and security features. It streamlines PDF manipulation tasks in .NET applications without the need for Adobe Acrobat.

Can IronPDF be used to print PDFs in an ASP.NET Web Application?

Yes, IronPDF can be integrated into ASP.NET Web Applications, enabling the generation and printing of PDF documents directly from web pages.

How can I ensure my PDF maintains formatting when printed from a URL?

IronPDF's RenderUrlAsPdf method retains the original formatting of web pages when converting them to PDF, ensuring that printed documents maintain their layout and style.

Is it necessary to have Adobe Acrobat Reader to create PDFs with IronPDF?

No, it's not necessary to have Adobe Acrobat Reader. IronPDF allows you to create, manipulate, and print PDFs without third-party applications.

What platforms does IronPDF support for PDF printing and generation?

IronPDF is compatible with multiple platforms, including Windows, macOS, Android, and iOS, making it a versatile tool for cross-platform development.

How can IronPDF enhance PDF documents with security features?

IronPDF provides the ability to add passwords and set permissions to secure PDF documents, ensuring that sensitive information is protected.

Can you generate PDF files with images from URLs using IronPDF?

Yes, IronPDF can convert URLs that contain images into PDF files, preserving the images' quality and layout within the document.

What functionalities does IronPDF provide for PDF content manipulation?

IronPDF allows for generating, editing, extracting content, merging, and splitting PDFs, as well as adding graphics and security features to documents.

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.
Talk to an Expert Five Star Trust Score Rating

Ready to Get Started?

Nuget Passed