USING IRONPRINT

How to Print a PDF from a Network Printer Using IronPDF

Published December 4, 2022
Share:

1. Introduction

This tutorial will show you how print PDFs from any printer on a network using IronPDF.

1.1 IronPDF Features

IronPDF is a potent PDF library that can convert from HTML to PDF with minimal loss of the original formatting shown in browsers. The .NET library for developers makes it easy to produce, read, and manipulate PDF files.

IronPDF converts HTML files to PDF files using the Chrome engine. IronPDF supports HTML, ASPX, Razor pages, and MVC Views, in addition to other web formats. IronPDF supports all Microsoft.NET technologies (both ASP.NET Web applications and traditional Windows applications).

IronPDF can be used to create visually stunning PDF documents. We can produce PDF documents with IronPDF from HTML5, Javascript, CSS, and images. There may also be headers and footers in the files. It is also easy to view PDF files using IronPDF.

  • Some of the sources that can be used to make a PDF file include HTML, HTML5, ASPX, and Razor/MVC View. We also have the option to convert picture files as well as HTML files to PDF
  • You can build interactive PDF files with IronPDF, fill out and submit interactive forms with it, merge and split PDF files, extract text and images from PDF files, search text within a PDF file, rasterize PDF pages to images, convert PDF to HTML, and print PDF files
  • A document can be generated using IronPDF from a URL. It also supports user agents, proxies, cookies, HTTP headers, and form variables for logins made behind HTML login forms
  • IronPDF can view and edit PDF files
  • Images can be extracted from documents using IronPDF
  • We can add headers, footers, text, images, bookmarks, watermarks, and more to documents with IronPDF
  • We can combine and divide pages in brand-new or recent documents using IronPDF
  • IronPDF can convert documents to PDFs without relying on Acrobat software
  • IronPDF can create PDFs from HTML files that use CSS files

2. Creating a New Project in Visual Studio

In this article, we are going to use a console application to generate PDF documents.

Open the Visual Studio software, and go to the File menu. Select "New Project", and then select "Console Application".

How to Print a PDF from a Network Printer, Figure 1

Enter the project name and select the file path in the appropriate text box. Then, click the Create button and select the required .NET Framework, as in the screenshot below.

How to Print a PDF from a Network Printer, Figure 2

The Visual Studio project will now generate the structure for the selected application. If you have selected the console, Windows, or the Web application template in the New Project wizard, Visual Studio will open the program.cs file, where you can enter code.

How to Print a PDF from a Network Printer, Figure 3

Next, we can add the library to test the code.

3. Install the IronPDF Library

The IronPDF Library can be downloaded and installed in four ways.

These are:

  1. Using Visual Studio NuGet Package Manager UI
  2. Using the Visual Studio Command Line
  3. Direct download from the NuGet website
  4. Direct download from the IronPDF website

3.1 Using Visual Studio NuGet Package Manager UI

Visual Studio provides the NuGet Package Manager UI for installing packages directly to a solution. The below screenshot shows how to open the NuGet Package Manager.

How to Print a PDF from a Network Printer, Figure 4

The Package Manager UI provides a search box to show the list of packages from the NuGet website. In the Package Manager, search for the IronPDF library using the keyword "IronPDF," as shown in the screenshot below.

How to Print a PDF from a Network Printer, Figure 5

In the above image, we can see the list of the related search items. We need to select the required option to install the package to the solution.

3.2 Using the Visual Studio Command-Line

In Visual Studio, go to Tools > NuGet Package Manager > Package Manager Console

Enter the following line in the package manager console tab:

Install-Package IronPrint

The package will download/install to the current project and be ready to use.

How to Print a PDF from a Network Printer, Figure 6

3.3 Direct download from the NuGet website

The third way to install IronPDF is to download the NuGet package directly from the website.

  1. Navigate to IronPDF's NuGet gallery page
  2. Select the "Download package" link from the menu on the right-hand side
  3. Double-click the downloaded package from the File Explorer to install it
  4. Reload the Visual Studio project

3.4 Direct download from the IronPDF website

Download the latest version of IronPDF directly from the website. Once downloaded, follow the steps below to add the package to the project.

  1. From Visual Studio, right-click the project from the Solution Explorer panel.
  2. Select the Add Reference option. Click the Browse button and search for the location of the downloaded reference.
  3. Click OK to add the reference.

4. Print PDF Files

IronPDF allows us to print PDF documents using a network printer driver. We can print PDF documents however many times we wish. Below is a code sample for printing on network printers.

try
{
    var ChromePdfRenderer = new ChromePdfRenderer();
    using (var pdfDocument = ChromePdfRenderer.RenderHtmlAsPdf("<h1>Hello world</h1>"))
    {
        using (var printDocument = pdfDocument.GetPrintDocument())
        {
            printDocument.PrinterSettings.PrinterName = "Brother DCP-T700W Printer";
            //Local p
            printDocument.PrinterSettings.printerName = "Microsoft Print to PDF" '
            printDocument.Print();
        }
}
catch(Exception ex)
{
    Console.WriteLine(ex.Message);
}
try
{
    var ChromePdfRenderer = new ChromePdfRenderer();
    using (var pdfDocument = ChromePdfRenderer.RenderHtmlAsPdf("<h1>Hello world</h1>"))
    {
        using (var printDocument = pdfDocument.GetPrintDocument())
        {
            printDocument.PrinterSettings.PrinterName = "Brother DCP-T700W Printer";
            //Local p
            printDocument.PrinterSettings.printerName = "Microsoft Print to PDF" '
            printDocument.Print();
        }
}
catch(Exception ex)
{
    Console.WriteLine(ex.Message);
}
Try
	Dim ChromePdfRenderer As New ChromePdfRenderer()
	Using pdfDocument = ChromePdfRenderer.RenderHtmlAsPdf("<h1>Hello world</h1>")
		Using printDocument = pdfDocument.GetPrintDocument()
			printDocument.PrinterSettings.PrinterName = "Brother DCP-T700W Printer"
			'Local p
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'			printDocument.PrinterSettings.printerName = "Microsoft Print to PDF" ' printDocument.Print(); } } catch(Exception ex) { Console.WriteLine(ex.Message); }
VB   C#

The above code helps us to print the created PDF document on the local or network printer programmatically. First, we create an object for the ChromePdfRenderer, which helps us to convert text, HTML code, URLs, and other documents into PDF documents. Various types of methods such as RenderHtmlAsPdf, RenderHTMLFileAsPdf, and RenderUrlAsPdf are used to perform various types of operations. With this sample code, we are using RenderHtmlAsPdf, as it allows us to convert the entered HTML code into a PDF document.

Once we have created an object for the ChromePdfRenderer by using the required method, we then need to use the method GetPrintDocument from the created object which allows us to access all the printer settings. This provides setting options such as page size, margin, DPI, etc. while we can further gain access to many more settings. We can also pass the printer name on the PrinterSettings.PrinterName property which allows us to print the pages from a specified printer. After specifying all the printer settings, we call the Print method, which will trigger printing on the specified printer. To use this method, you will need to add an assembly reference to the System.Drawing.dll.

IronPDF does not have any restrictions on printing documents. We can print any number of documents as required. If we do not specify a printer name, it will print from the default printer.

5. Conclusion

IronPDF is one of the best-known PDF libraries. It functions independently of all other libraries, and your computer does not need to have Adobe Reader installed. It also works on a variety of platforms. The initial price point for IronPDF is $749.00 There is an option to make a one-year payment for product maintenance and upgrades. IronPDF also provides coverage for royalty-free SaaS and OEM redistribution at an extra cost.

For further details on pricing, go here.

< PREVIOUS
How to Print PDF Files in C# Without Using Adobe
NEXT >
How To Print PDF Files in .NET Core

Ready to get started? Version: 2024.10 just released

Free NuGet Download Total downloads: 10,762 View Licenses >