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
Printing functionality is a critical aspect of PDF manipulation libraries, allowing developers to generate high-quality printed documents directly from their applications. In this article, we will compare the printing capabilities of two popular libraries, IronPDF and PDFSharp, in the context of C# or .NET development. We'll explore the strengths and limitations of each library, shedding light on their approaches to printing PDF files.
PDFsharp is the Open Source .NET library that easily creates and processes PDF documents on the fly from any .NET language program files. The same drawing routines can be used to create documents, draw on the screen, or send output to any arbitrary IP printer name.
IronPDF is a popular library for C# .NET that enables developers to work with PDF files in a versatile and efficient manner. It provides a comprehensive set of functionalities for creating, reading, modifying, and converting PDF documents, making it an all-in-one solution for PDF-related tasks. One of its key features is the ability to convert HTML content to PDF, making it ideal for generating PDFs from web pages and dynamic content. IronPDF also supports advanced features like adding watermarks, digital signatures, post attachments, and interactive form fields to PDFs. With its easy-to-use API and robust performance, IronPDF has become a favored choice among developers for seamless PDF manipulation in the C# environment.
PDFsharp does not provide any functions to print PDF files. However, we can use Acrobat with PDFsharp to print PDF documents. Please note that you will not be able to print PDF files using Acrobat in the latest version of PDFsharp. You need to install the 1.3.0 version of PDFsharp to print the PDF documents in C# .NET. You must have Adobe Reader installed on your machine. If you don't have an Adobe Reader installed, you can download and install one.
Installing the PDFsharp library is a straightforward process. PDFsharp is available as a NuGet package, which allows you to easily add it to your C# or .NET project. Here are the steps to install PDFsharp using NuGet:
In the NuGet Package Manager, you'll see a "Browse" tab. Type "PDFsharp" into the search bar and press Enter. This will display a list of available PDFsharp packages.
PdfSharp
package and select the 1.3.0 version.PDF printing with PDFsharp is not a simple task. We need Adobe Acrobat Reader installed in your system. PDFsharp doesn't provide any function to print PDF files. We will first start the Adobe Reader process using PDFsharp and then print the document using the Adobe Reader process.
The following line of code demonstrates the example of printing a PDF file:
internal class Program
{
static void Main(string[] args)
{
// Set the path to the Adobe Acrobat Reader executable
PdfFilePrinter.AdobeReaderPath = @"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe";
// Create a PdfFilePrinter object with the path to the PDF and printer name
PdfFilePrinter printer = new PdfFilePrinter(@"D:\Tutorial Project\PDFSharpPrintPDF\SamplePDF.pdf", "Microsoft Print To PDF");
try
{
// Print the PDF document
printer.Print();
}
catch (Exception ex) // Catch any exceptions during printing
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
internal class Program
{
static void Main(string[] args)
{
// Set the path to the Adobe Acrobat Reader executable
PdfFilePrinter.AdobeReaderPath = @"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe";
// Create a PdfFilePrinter object with the path to the PDF and printer name
PdfFilePrinter printer = new PdfFilePrinter(@"D:\Tutorial Project\PDFSharpPrintPDF\SamplePDF.pdf", "Microsoft Print To PDF");
try
{
// Print the PDF document
printer.Print();
}
catch (Exception ex) // Catch any exceptions during printing
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
PdfFilePrinter.AdobeReaderPath
sets the path to the Acrobat Reader executable (Acrobat.exe) on your system. It tells the PdfFilePrinter
where to find the Acrobat application, which is needed for the printing process. Make sure to add the correct path, else it will not work.PdfFilePrinter
object is created. The constructor takes two arguments: The first argument is the path to the PDF file you want to print. The second argument is the name of the printer to which you want to send the print job ("Microsoft Print To PDF" in this case). You can replace this with the name of your desired printer.Print
method of PdfFilePrinter
. It is enclosed in a try-catch
block to handle any exceptions that may occur during the printing process. If an exception occurs, the error message will be displayed on the console.Installing IronPDF in your project is a very straightforward process.
IronPdf
package offered by Iron Software, and click on it to select.On the right side of the "NuGet Package Manager" window, you will see a list of projects in your solution. Choose the project(s) where you want to install the package. Typically, you will select the main project where you'll be working with PDF documents.
IronPdf
package to your project(s). NuGet will download and install the package along with any required dependencies.That's it! Now you have successfully installed the IronPDF NuGet package in your Visual Studio 2022 C# project, and you can start using its classes and methods to work with PDF documents.
Printing a PDF file using IronPDF is a quite simple task. Unlike PDFsharp, IronPDF provides a function to print the PDF document. IronPDF provides printing settings and other required methods to print documents. We do not need to use any other process or third-party library. The following line of code demonstrates the example of printing a PDF file using IronPDF.
static void Main(string[] args)
{
// Create a new PDF document from the specified file path
PdfDocument pdfDocument = new PdfDocument(@"D:\Tutorial Project\PDFSharpPrintPDF\SamplePDF.pdf");
// Print the PDF document using the default printer
pdfDocument.Print();
}
static void Main(string[] args)
{
// Create a new PDF document from the specified file path
PdfDocument pdfDocument = new PdfDocument(@"D:\Tutorial Project\PDFSharpPrintPDF\SamplePDF.pdf");
// Print the PDF document using the default printer
pdfDocument.Print();
}
PdfDocument
class from IronPDF with a PDF document from the specified file path. The path points to the location of the PDF file you want to print ("SamplePDF.pdf" in this case). The PdfDocument
class represents a PDF document that you can work with using IronPDF.Print
method is called on the PdfDocument
instance. In the context of IronPDF, the Print
method sends the PDF document to the default printer installed on the machine, initiating the printing process.You can also specify a different printer using the following code:
// Set the printer name to a specific printer
pdfDocument.GetPrintDocument().PrinterSettings.PrinterName = "my Printer";
// Set the printer name to a specific printer
pdfDocument.GetPrintDocument().PrinterSettings.PrinterName = "my Printer";
PrinterName
property in the PrinterSettings
.IronPDF and PDFsharp are both powerful libraries for working with PDF files in C# or .NET. However, IronPDF offers a more modern and feature-rich solution, providing functionalities for creating, reading, modifying, and converting PDFs, along with support for HTML-to-PDF conversion. IronPDF's straightforward API and streamlined approach make it easy for developers to work with PDFs directly within their applications. On the other hand, PDFsharp, while capable, requires an external application like Acrobat for certain tasks, such as printing PDFs, making it comparatively less convenient for handling the entire PDF workflow.
IronPDF is free for development and comes with a free trial for commercial use.
IronPrint is Iron Software's new .NET printing library, offering compatibility across multiple platforms, such as Windows, macOS, Android, and iOS.
IronPDF allows developers to create, read, modify, and convert PDF documents. It supports converting HTML content to PDF, adding watermarks, digital signatures, attachments, and interactive form fields.
No, PDFsharp does not provide functions to print PDF files directly. It requires the use of Adobe Acrobat Reader to print PDF documents.
In Visual Studio, right-click on your project's solution, select 'Manage NuGet Packages for Solution...', search for 'PDFsharp', choose the 1.3.0 version, and click 'Install'.
To print a PDF with PDFsharp, use Adobe Acrobat Reader by setting up the AdobeReaderPath and creating a PdfFilePrinter object to handle the printing process.
In Visual Studio, right-click on your project, select 'Manage NuGet Packages...', search for 'IronPDF', select your project, and click 'Install'.
Create a PdfDocument instance with the PDF file path, then call the Print method to send the document to the default printer.
Yes, you can specify a different printer by setting the PrinterName property in the PrinterSettings of the PdfDocument.
IronPDF offers a more modern and feature-rich solution for handling PDFs, including HTML-to-PDF conversion and a straightforward API, without needing external applications for printing.
Yes, IronPDF is free for development and provides a free trial for commercial use.