Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
This tutorial will show you how print PDFs from any printer on a network using IronPDF.
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.
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".
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.
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.
Next, we can add the library to test the code.
The IronPDF Library can be downloaded and installed in four ways.
These are:
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.
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.
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.
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.
The third way to install IronPDF is to download the NuGet package directly from the website.
Download the latest version of IronPDF directly from the website. Once downloaded, follow the steps below to add the package to the project.
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); }
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.
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.
9 .NET API products for your office documents