Skip to footer content
PRODUCT COMPARISONS

PdfiumViewer Print PDF in C# (Alternative Tutorial)

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#:

  • IronPDF
  • PDFiumViewer

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

Overview of IronPDF

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:

  • Convert HTML, CSS, and images to PDF files.
  • Generate PDF documents from scratch.
  • Edit existing PDFs.
  • Support various PDF document elements like images, text, tables, and forms.
  • Provide advanced functionalities such as digital signatures, watermarks, and encryption.
  • Enable silent printing without any third-party tools or libraries.
  • Offer a user-friendly interface and comprehensive documentation.

PDFiumViewer

Overview of PDFiumViewer

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:

  • The ability to render PDFs and display them in Windows Forms applications.
  • Support for navigation, zooming, and text selection within PDF documents.
  • A straightforward integration process for Windows Forms projects.

Installing IronPDF

To start using IronPDF, follow these steps to install it using the NuGet Package Manager in Visual Studio:

  1. Open Visual Studio and create a new Console Application or open an existing one.

    PdfiumViewer Print PDF in C# (Alternative Tutorial) Figure 1 - New Project- PDFiumViewer Print PDF C#

  2. Right-click on the project in the Solution Explorer and select "Manage NuGet Packages."
  3. Switch to the "Browse" tab, search for "IronPDF," and click "Install."

    PdfiumViewer Print PDF in C# (Alternative Tutorial) Figure 2 - IronPDF Installation

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.

Installing PDFiumViewer

You can install PDFiumViewer via the NuGet Package Manager as well. Here's how:

  1. Open your Visual Studio project and create a Windows Forms application.

    PdfiumViewer Print PDF in C# (Alternative Tutorial) Figure 3 - New Project

  2. Drag a button to the Form and name it "Print PDF".

    PdfiumViewer Print PDF in C# (Alternative Tutorial) Figure 4 - Print Button

  3. Right-click on the project in the Solution Explorer and choose "Manage NuGet Packages."
  4. In the "NuGet Package Manager" window, switch to the "Browse" tab, search for "PDFiumViewer" and click "Install."

    PdfiumViewer Print PDF in C# (Alternative Tutorial) Figure 5 - PDFiumViewer Installation

  5. 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.

    PdfiumViewer Print PDF in C# (Alternative Tutorial) Figure 6 - PDFiumViewer.Native

Once the installation is complete, you can start using PDFiumViewer for printing PDF files and other PDF-related tasks.

Printing PDFs with IronPDF

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
$vbLabelText   $csharpLabel

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.

Output

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.

PdfiumViewer Print PDF in C# (Alternative Tutorial) Figure 7 - Print Dialog

The output saved is a pixel-perfect PDF document:

PdfiumViewer Print PDF in C# (Alternative Tutorial) Figure 8 - PDF Output

Printing PDFs with PDFiumViewer

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
$vbLabelText   $csharpLabel

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.

PdfiumViewer Print PDF in C# (Alternative Tutorial) Figure 9 - Save as PDF

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.

PdfiumViewer Print PDF in C# (Alternative Tutorial) Figure 10 - Output

Conclusion

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.

Frequently Asked Questions

What is a robust C# library for creating, manipulating, and processing PDFs?

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.

What features does this library offer for working with PDFs?

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.

What is a popular C# library for displaying and rendering PDFs in Windows Forms applications?

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.

How do you install a C# library for PDF manipulation using NuGet Package Manager?

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.

How do you install a library for viewing PDFs in Windows Forms?

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.

Can a specific C# library print PDFs directly?

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.

Can this library natively print PDFs?

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.

What are the advantages of using a comprehensive PDF library in C#?

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.

Is there a library suitable for displaying PDFs in Windows Forms?

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.

Which library should I choose for my project needs?

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.

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