Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Barcodes serve as unique identifiers that store information in a visually scannable format. They are widely used in retail, logistics, healthcare, and many other industries for tasks such as inventory management, product labeling, and asset tracking. Printing barcodes is essential for streamlining operations, reducing errors, and enhancing overall efficiency in data management.
Barcodes play a crucial role in modern-day business operations, facilitating efficient tracking, inventory management, and quick data retrieval.
In this article, we will explore how to generate barcodes and print them in C# using IronBarcode, IronPDF, and IronPrint libraries.
Developed by Iron Software, IronPrint is a robust print library designed for .NET, elevating C# printing capabilities. Let's explore the key features that make IronPrint stand out, making it a valuable companion when working alongside IronBarcode and IronPDF in a C# console application.
IronPrint puts you in control, allowing easy customization of various printing aspects. From choosing paper size, adjusting DPI, and setting margins to specifying the number of copies, printer name, and even grayscale printing, IronPrint ensures flexibility.
The introduction of the Printer class is a game-changer. It provides a set of methods for effortlessly handling the printing of different file types, from images to PDF documents. This versatility adds a layer of flexibility to your printing options.
IronPrint is versatile, supporting various platforms such as Windows, macOS, Android, and iOS. This cross-platform compatibility ensures a consistent printing experience across different application environments.
1. Fine-Tuned Print Settings: IronPrint allows you to dive into print settings, giving you precise control over elements like paper size, orientation, DPI, and more. This level of customization ensures that your printed output meets your specific requirements.
2. Printer Class Convenience: The Printer class expands your possibilities, enabling you to print not just documents but a variety of file types effortlessly. The methods offered by the Printer class streamline your printing workflows tailored to your application's needs.
3. Platform-Friendly: IronPrint's commitment to supporting multiple platforms makes it an ideal choice for developers working on applications for different environments. Whether it's a desktop application on Windows or a mobile app on iOS or Android, IronPrint delivers a reliable printing experience.
Before diving into the steps of creating a C# console application to print Barcodes, ensure you have the following prerequisites:
Follow these steps to set up a C# console application in Visual Studio:
Follow the steps to install the necessary libraries:
In the browse tab of NuGet, search for the libraries and click install.
Install Barcode Library - IronBarcode:
Install-Package BarCode
Install IronPDF PDF Library:
Using the NuGet Package Manager Console
Install-Package BarCode
Install IronPrint Printing Library:
Using the NuGet Package Manager Console, enter the following command:
Install-Package BarCode
Let's break down the process of generating barcodes, converting the generated barcode image to PDF and finally printing the barcode in a step-by-step procedure using IronBarcode, IronPDF, and IronPrint.
In the Program.cs file at the top, we will include references to the required libraries. This ensures that the libraries are installed and ready to be used.
// Reference to libraries
using IronPrint; // Library for printing functionalities
using IronPdf; // Library for PDF handling
using IronBarcode; // Library for barcode generation
using IronSoftware.Drawing; // Library for image processing
// Reference to libraries
using IronPrint; // Library for printing functionalities
using IronPdf; // Library for PDF handling
using IronBarcode; // Library for barcode generation
using IronSoftware.Drawing; // Library for image processing
' Reference to libraries
Imports IronPrint ' Library for printing functionalities
Imports IronPdf ' Library for PDF handling
Imports IronBarcode ' Library for barcode generation
Imports IronSoftware.Drawing ' Library for image processing
Here, we use IronBarcode to create a barcode and save it as an image. We can even generate a barcode of QR code type.
// Code to generate a barcode
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8); myBarcode.SaveAsImage("assets/barcode.png");
// Code to generate a barcode
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8); myBarcode.SaveAsImage("assets/barcode.png");
' Code to generate a barcode
Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.EAN8)
myBarcode.SaveAsImage("assets/barcode.png")
In this source code:
Here is the output barcode image:
Optionally, convert the barcode image to a PDF using IronPDF. This preserves the formatting and gives more control over size and printing functionalities.
// Code to convert barcode image to PDF using IronPDF ImageToPdfConverter.ImageToPdf("assets/barcode.png").SaveAs("assets/composite.pdf");
// Code to convert barcode image to PDF using IronPDF ImageToPdfConverter.ImageToPdf("assets/barcode.png").SaveAs("assets/composite.pdf");
' Code to convert barcode image to PDF using IronPDF ImageToPdfConverter.ImageToPdf("assets/barcode.png").SaveAs("assets/composite.pdf");
The barcode.png file is saved as a PDF document. Each image is placed on a separate page. Here is the output:
Configure print settings such as paper size, margins, and printer name using IronPrint.
// Code to adjust PrinterSettings using IronPrint
List<string> printerNames = Printer.GetPrinterNames();
PrintSettings printerSettings = new PrintSettings();
foreach(string printerName in printerNames)
{
if(printerName.Equals("Microsoft Print to PDF"))
printerSettings.PrinterName = printerName;
}
printerSettings.PaperSize = PaperSize.A4;
Margins margins = new Margins(30, 10);
printerSettings.PaperMargins = margins;
// Code to adjust PrinterSettings using IronPrint
List<string> printerNames = Printer.GetPrinterNames();
PrintSettings printerSettings = new PrintSettings();
foreach(string printerName in printerNames)
{
if(printerName.Equals("Microsoft Print to PDF"))
printerSettings.PrinterName = printerName;
}
printerSettings.PaperSize = PaperSize.A4;
Margins margins = new Margins(30, 10);
printerSettings.PaperMargins = margins;
' Code to adjust PrinterSettings using IronPrint
Dim printerNames As List(Of String) = Printer.GetPrinterNames()
Dim printerSettings As New PrintSettings()
For Each printerName As String In printerNames
If printerName.Equals("Microsoft Print to PDF") Then
printerSettings.PrinterName = printerName
End If
Next printerName
printerSettings.PaperSize = PaperSize.A4
Dim margins As New Margins(30, 10)
printerSettings.PaperMargins = margins
The above sample code provides PrinterSettings options that gives more control over the printing process in any .NET barcode generator application.
For more Printing options, please visit the code examples page.
Finally, trigger the barcode printing using IronPrint as shown in the following code:
// Code to print
Printer.Print("assets/composite.pdf", printerSettings);
// Code to print
Printer.Print("assets/composite.pdf", printerSettings);
' Code to print
Printer.Print("assets/composite.pdf", printerSettings)
Although IronPrint provides the facility to print directly from the image format, here we are printing it from PDF. Here is the output PDF file by IronPrint:
IronPrint is specifically designed as a powerful print library for .NET applications. Unlike IronPDF, which is primarily focused on handling PDF-related tasks, and C# Microsoft printing, which is a general-purpose printing mechanism, IronPrint provides a dedicated set of classes and methods tailored for fine-grained control over the printing process.
With IronPrint, developers can leverage:
These advantages make IronPrint a preferred choice when developers require a specialized and feature-rich printing library, offering greater control and customization options compared to more generalized printing solutions.
In conclusion, IronBarcode provides a seamless solution for generating barcodes in C#, and when combined with IronPrint, the process of printing these barcodes becomes highly efficient. By following the outlined steps and taking advantage of the features provided by IronPrint, developers can integrate barcode generation and printing into their C# applications with ease.
For more information on how to print efficiently, please visit this documentation page.
IronPrint offers a free trial to explore its complete functionality and capabilities. Perpetual license options are available for various needs, starting from $749. Download the library from here and enhance your C# application with printing capabilities.
9 .NET API products for your office documents