Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
PDF documents play a crucial role in various software applications, including generating invoices, displaying reports, and sharing information. When it comes to working with PDFs in C#, developers have multiple options. This article explores two popular libraries for printing PDFs using Microsoft Print in C#:
Let's delve into their features and ease of use and compare their printing capabilities to help you make an informed decision for your next C# project.
IronPDF is a robust C# library designed for creating, manipulating, and processing PDFs effortlessly. It offers a wide range of features, making it a preferred choice among developers. IronPDF stands out for its ability to:
PDFiumViewer is another popular option for working with PDFs in C#. Built on top of the open-source PDFium project, it provides a .NET wrapper for its functionality. PDFiumViewer offers:
To start using IronPDF, follow these steps to install it using the NuGet Package Manager in Visual Studio:
Open Visual Studio and create a new Console Application or open an existing one.
Switch to the "Browse" tab, search for "IronPDF," and click "Install."
With IronPDF successfully installed, we can begin using it for printing PDFs and other PDF document-related tasks. Before that, let's also install PDFiumViewer in our system.
You can install PDFiumViewer via the NuGet Package Manager as well. Here's how:
Open your Visual Studio project and create a Windows Forms application.
Drag a button to the Form and name it "Print PDF".
In the "NuGet Package Manager" window, switch to the "Browse" tab, search for "PDFiumViewer" and click "Install."
Alternatively, to install the PDFium DLL, you can search for "PDFiumViewer.Native" 32-bit or 64-bit, depending on your OS requirements. This DLL is necessary to load PDF files or pages using PDFiumViewer in a Windows Forms application.
Once the installation is complete, you can start using PDFiumViewer for printing PDF files and other PDF-related tasks.
Printing PDFs using IronPDF is straightforward. Here's the source code example demonstrating how to print a PDF file without a printer name:
using IronPdf;
class Program
{
static void Main()
{
// Create a new PDF renderer
var renderer = new ChromePdfRenderer();
// Render a PDF from a URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com");
// Print the PDF document, 300 dpi, without printer name
pdf.Print(300, true);
}
}
using IronPdf;
class Program
{
static void Main()
{
// Create a new PDF renderer
var renderer = new ChromePdfRenderer();
// Render a PDF from a URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://ironpdf.com");
// Print the PDF document, 300 dpi, without printer name
pdf.Print(300, true);
}
}
Imports IronPdf
Friend Class Program
Shared Sub Main()
' Create a new PDF renderer
Dim renderer = New ChromePdfRenderer()
' Render a PDF from a URL
Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://ironpdf.com")
' Print the PDF document, 300 dpi, without printer name
pdf.Print(300, True)
End Sub
End Class
In this code example, IronPDF efficiently renders a PDF from a URL and sends it to the default printer for printing. The method Print
is configured for a resolution of 300 DPI, allowing silent printing without prompting the user. For more advanced printing options, please visit the C# Print PDF Documents.
Upon executing the project, the Print method displays a print dialog to save the file as a PDF. If the default printer is set to a physical printer, the document will be printed directly.
The output saved is a pixel-perfect PDF document:
While PDFiumViewer excels in rendering and displaying PDFs, it doesn't provide native PDF printing capabilities. To print a PDF document using PDFiumViewer, you'll need to utilize additional third-party drawing tools or libraries. To print directly using PDFiumViewer, we need to use Microsoft's System.Drawing.Printing assembly along with the PDFiumViewer library.
In the following code, first, we load the PDF using the PdfDocument.Load
method. Then, we create a printing object called printDocument
using the CreatePrintDocument
method, which comes from the System.Drawing.Printing
namespace. Finally, we use the Print
method to send the loaded PDF to the printer for printing.
using System;
using System.Drawing.Printing;
using PdfiumViewer;
class Program
{
static void Main()
{
string pathToFile = @"C:\assets\input.pdf"; // Absolute path with filename
// Load the PDF document
using (var pdf = PdfDocument.Load(pathToFile))
{
// Create a print document for the loaded PDF
var printDocument = pdf.CreatePrintDocument();
// Print the document
printDocument.Print();
}
}
}
using System;
using System.Drawing.Printing;
using PdfiumViewer;
class Program
{
static void Main()
{
string pathToFile = @"C:\assets\input.pdf"; // Absolute path with filename
// Load the PDF document
using (var pdf = PdfDocument.Load(pathToFile))
{
// Create a print document for the loaded PDF
var printDocument = pdf.CreatePrintDocument();
// Print the document
printDocument.Print();
}
}
}
Imports System
Imports System.Drawing.Printing
Imports PdfiumViewer
Friend Class Program
Shared Sub Main()
Dim pathToFile As String = "C:\assets\input.pdf" ' Absolute path with filename
' Load the PDF document
Using pdf = PdfDocument.Load(pathToFile)
' Create a print document for the loaded PDF
Dim printDocument = pdf.CreatePrintDocument()
' Print the document
printDocument.Print()
End Using
End Sub
End Class
Note: PDFiumViewer requires a System.Windows.Forms
assembly to work; otherwise, it will throw an exception. This is because the PDFiumViewer library is designed to be used with Windows Forms applications. Ensure this task is performed in a valid Windows Forms application.
On executing the app, the Windows form is displayed with a "Print PDF" button. Upon clicking, the print dialog is displayed. Save the document as a PDF file.
The output is the same as the input PDF file. If the printer settings had the physical printer name, then it would have been printed out on paper perfectly.
IronPDF and PDFiumViewer both serve distinct purposes when it comes to working with PDFs. IronPDF offers a comprehensive set of features for creating, manipulating, and printing PDFs. Its ease of use and rich functionality make it a popular choice for .NET developers.
On the other hand, PDFiumViewer shines in rendering and displaying PDFs within Windows Forms applications. However, it lacks native PDF printing capabilities, and additional solutions for printing, as shown in the above example, may be required.
The choice between IronPDF and PDFiumViewer depends on your specific project requirements. If you need access to a versatile library with robust PDF manipulation features, IronPDF is an excellent choice. On the other hand, if your focus is on displaying PDFs in a Windows Forms application, PDFiumViewer can fulfill that role.
IronPDF is a powerful PDF library for C# developers. It is free for development purposes, and commercial licenses start at $749 for a single developer. There is also a free trial with full features and support, so you can try it out before buying. You can download the software from here.
IronPDF is a robust C# library designed for creating, manipulating, and processing PDFs effortlessly. It offers features like converting HTML to PDF, generating PDF documents from scratch, editing existing PDFs, and enabling silent printing.
IronPDF can convert HTML, CSS, and images to PDF, generate and edit PDFs, support various PDF elements, and provide functionalities such as digital signatures, watermarks, and encryption.
PDFiumViewer is a popular C# library built on the open-source PDFium project. It provides a .NET wrapper for displaying and rendering PDFs in Windows Forms applications.
To install IronPDF, open Visual Studio, create or open a project, right-click on the project, select 'Manage NuGet Packages', and search for 'IronPDF' in the Browse tab. Click 'Install' to add it to your project.
To install PDFiumViewer, open your Visual Studio project, create a Windows Forms application, manage NuGet packages, search for 'PDFiumViewer', and click 'Install'. Optionally, install 'PDFiumViewer.Native' for additional support.
Yes, IronPDF can print PDFs using its built-in library functions. It allows for silent printing directly from C# applications without the need for third-party tools.
PDFiumViewer does not have native PDF printing capabilities. Printing requires additional tools or libraries, such as Microsoft's System.Drawing.Printing assembly, to handle print tasks.
IronPDF offers extensive features for PDF creation, manipulation, and printing. It supports HTML conversion, advanced PDF functionalities, and provides comprehensive documentation and a user-friendly interface.
Yes, PDFiumViewer is excellent for rendering and displaying PDFs within Windows Forms applications. It supports navigation, zooming, and text selection but lacks direct printing capabilities.
The choice depends on your project needs. IronPDF is better for comprehensive PDF manipulation and printing, while PDFiumViewer is ideal for displaying PDFs in Windows Forms applications.