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
In the ever-evolving landscape of software development, the ability to generate and print Word documents programmatically is a fundamental requirement. C# developers often encounter scenarios where generating and printing Word documents becomes essential for tasks such as report generation, document processing, or creating professional-looking outputs. To address this need, Iron Software presents IronWord, IronPDF, and IronPrint, powerful libraries designed to streamline the creation, manipulation, and printing of Word and PDF documents within C# applications.
This article will explore the features and advantages of IronPrint for printing, creating a Word document object sender using IronWord, and converting it to PDF using IronPDF for printing.
WordDocument
classSaveAs
methodDocxToPdfRenderer
methodPrinterSettings
using IronPrintPrinter.Print
methodIronPrint, developed by Iron Software, is a robust and versatile print library for .NET, offering a wide array of tools for handling printing tasks in C#. It stands out with dedicated classes and methods tailored for print-related functionalities, providing developers with fine-grained control over the printing process and printer settings.
IronPrint empowers developers to customize various aspects of the printing process. This includes:
One of the standout features of IronPrint is the introduction of the Printer
class. This class provides a comprehensive set of methods for printing various file types, encompassing images and PDF documents. The versatility of the Printer class allows for seamless integration into diverse printing scenarios. It also allows displaying a print dialog while printing in real-time applications, giving more granular control for printing Word documents.
IronPrint boasts cross-platform compatibility, making it suitable for deployment across multiple environments. Whether your application runs on Windows, macOS, Android, or iOS, IronPrint ensures consistent and reliable printing functionality.
Before diving into the implementation, ensure you have the following prerequisites:
Follow these steps to set up a C# console application, create a Word document object, convert it to PDF, and finally print it using IronWord, IronPDF, and IronPrint respectively.
Install IronPrint Printing Library:
Using the NuGet Package Manager Console, use the following command:
Install-Package IronPrint
Install-Package IronPrint
Do the same for installing IronWord and IronPDF library using the Manage NuGet Packages for Solutions. To install IronWord and IronPDF using the NuGet Package Manager Console, use the following commands:
Install-Package IronWord
Install-Package IronPdf
Install-Package IronWord
Install-Package IronPdf
Let's begin by creating a simple Word document using IronWord. The following code snippet illustrates how to create a Word document with sample text and save it:
using IronWord;
using IronWord.Models;
// Code to Create Word File
// Create a TextRun object with sample text
TextRun textRun = new TextRun("Sample text");
// Create a paragraph and add the TextRun to it
Paragraph paragraph = new Paragraph();
paragraph.AddTextRun(textRun);
// Create a Word document object with the paragraph and save it as a .docx file
WordDocument doc = new WordDocument(paragraph);
doc.SaveAs("assets/document.docx");
using IronWord;
using IronWord.Models;
// Code to Create Word File
// Create a TextRun object with sample text
TextRun textRun = new TextRun("Sample text");
// Create a paragraph and add the TextRun to it
Paragraph paragraph = new Paragraph();
paragraph.AddTextRun(textRun);
// Create a Word document object with the paragraph and save it as a .docx file
WordDocument doc = new WordDocument(paragraph);
doc.SaveAs("assets/document.docx");
Imports IronWord
Imports IronWord.Models
' Code to Create Word File
' Create a TextRun object with sample text
Private textRun As New TextRun("Sample text")
' Create a paragraph and add the TextRun to it
Private paragraph As New Paragraph()
paragraph.AddTextRun(textRun)
' Create a Word document object with the paragraph and save it as a .docx file
Dim doc As New WordDocument(paragraph)
doc.SaveAs("assets/document.docx")
In this code:
TextRun
containing the sample text.Paragraph
is created, and the TextRun
is added to it.WordDocument
is created with the paragraph, and the new document is saved as "document.docx".Once we have our Word document, we may need to convert it to a PDF format. IronPDF simplifies this process, allowing for seamless conversion. Here's the code snippet:
using IronPdf;
// Code to convert DOCX file to PDF using IronPDF
// Create a DocxToPdfRenderer instance
var renderer = new DocxToPdfRenderer();
// Render the DOCX document as a PDF
var pdf = renderer.RenderDocxAsPdf("assets/document.docx");
// Save the resulting PDF
pdf.SaveAs("assets/word.pdf");
using IronPdf;
// Code to convert DOCX file to PDF using IronPDF
// Create a DocxToPdfRenderer instance
var renderer = new DocxToPdfRenderer();
// Render the DOCX document as a PDF
var pdf = renderer.RenderDocxAsPdf("assets/document.docx");
// Save the resulting PDF
pdf.SaveAs("assets/word.pdf");
Imports IronPdf
' Code to convert DOCX file to PDF using IronPDF
' Create a DocxToPdfRenderer instance
Private renderer = New DocxToPdfRenderer()
' Render the DOCX document as a PDF
Private pdf = renderer.RenderDocxAsPdf("assets/document.docx")
' Save the resulting PDF
pdf.SaveAs("assets/word.pdf")
In this code:
Printing the PDF can be achieved using IronPrint, providing flexibility and control over the print settings. If print settings are not set, then default settings are used to print. The following code demonstrates how to print the generated PDF:
using IronPrint;
using System.Collections.Generic;
// Code for Printing using IronPrint
// Fetch printer names available in the system
List<string> printerNames = Printer.GetPrinterNames();
// Configure print settings
PrintSettings printerSettings = new PrintSettings();
foreach(string printerName in printerNames)
{
if(printerName.Equals("Microsoft Print to PDF"))
{
printerSettings.PrinterName = printerName;
}
}
// Set paper size to A4 and configure margins
printerSettings.PaperSize = PaperSize.A4;
Margins margins = new Margins(30, 10);
printerSettings.PaperMargins = margins;
// Print the PDF with the specified settings
Printer.Print("assets/word.pdf", printerSettings);
using IronPrint;
using System.Collections.Generic;
// Code for Printing using IronPrint
// Fetch printer names available in the system
List<string> printerNames = Printer.GetPrinterNames();
// Configure print settings
PrintSettings printerSettings = new PrintSettings();
foreach(string printerName in printerNames)
{
if(printerName.Equals("Microsoft Print to PDF"))
{
printerSettings.PrinterName = printerName;
}
}
// Set paper size to A4 and configure margins
printerSettings.PaperSize = PaperSize.A4;
Margins margins = new Margins(30, 10);
printerSettings.PaperMargins = margins;
// Print the PDF with the specified settings
Printer.Print("assets/word.pdf", printerSettings);
Imports IronPrint
Imports System.Collections.Generic
' Code for Printing using IronPrint
' Fetch printer names available in the system
Private printerNames As List(Of String) = Printer.GetPrinterNames()
' Configure print settings
Private 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
' Set paper size to A4 and configure margins
printerSettings.PaperSize = PaperSize.A4
Dim margins As New Margins(30, 10)
printerSettings.PaperMargins = margins
' Print the PDF with the specified settings
Printer.Print("assets/word.pdf", printerSettings)
In this code:
Printer.GetPrinterNames()
.Printer.Print()
method.If you want to get control over NumberOfCopies
, Print multiple pages, Grayscale
, and DPI
please visit this code examples page. You can also enable a printer dialog and prevent silent printing of documents.
Here are some key advantages of using IronPrint for printing jobs in C# console or Windows forms applications:
IronPrint provides asynchronous functions, allowing print operations to be performed asynchronously. This prevents print operations from blocking threads, leading to enhanced performance and responsiveness in your application.
The dedicated Printer
class in IronPrint offers a comprehensive set of methods for printing various file types, including images and PDF documents. This versatility provides flexibility beyond standard printing, allowing developers to handle different types of content with ease.
IronPrint supports printing across multiple platforms, including Windows, Android, iOS, and macOS. This cross-platform compatibility makes it suitable for a variety of application environments, ensuring that your printing functionality can be deployed across diverse operating systems.
IronPrint allows developers to finely control print settings, providing a high degree of customization. Developers can specify various aspects of the printing process, such as paper size, orientation, DPI, number of copies, printer name, margins, and grayscale printing, through the PrintSettings
class.
IronPrint integrates seamlessly with other Iron Software libraries, such as IronQR and IronPDF. This integration allows developers to create, convert, and print QR codes, PDFs, and other documents within a unified and efficient workflow.
IronPrint features a user-friendly API that simplifies the implementation of printing functionality in C# applications. Developers can quickly add barcode and printing capabilities to their projects, reducing development time and effort.
IronPrint is backed by comprehensive documentation and support from Iron Software. This ensures that developers have access to resources and assistance when implementing printing features, making it easier to troubleshoot issues and optimize the printing process.
With IronPrint, developers have enhanced control over the printing process. Features such as the ability to set paper size, margins, and other print parameters allow for precise control, ensuring that the printed output meets specific requirements and standards.
By following these steps, you can seamlessly integrate Word document handling, conversion to PDF, and printing functionality into your C# applications. IronWord, IronPDF, and IronPrint collectively provide a powerful toolkit for developers looking to enhance their document-related tasks. Whether you're working on web, mobile, desktop, or console applications, this guide serves as a comprehensive resource for leveraging these libraries effectively in your .NET projects.
For more information on how to print efficiently, please visit this documentation page.
IronPrint options are available for various needs, starting from $749. Download the library and enhance your C# application with printing capabilities.
IronPrint is a robust and versatile print library for .NET developed by Iron Software. It offers tools for handling printing tasks in C#, providing developers with fine-grained control over the printing process and printer settings.
To print a Word document in C# using IronPrint, follow these steps: create a Visual Studio Project, install IronWord, IronPDF, and IronPrint libraries, create a Word Document using IronWord, convert it to PDF using IronPDF's DocxToPdfRenderer method, and use IronPrint for printing.
IronPrint features comprehensive print settings customization, versatile printing with the Printer class, and cross-platform support, making it suitable for deployment across multiple environments.
To use IronPrint, you need to have Visual Studio installed, along with IronWord, IronPDF, and IronPrint libraries. These can be installed via the NuGet Package Manager Console.
Create a Word document using IronWord by creating a TextRun with sample text, adding it to a Paragraph, and then creating a WordDocument with the paragraph. Save it using the SaveAs method.
Use IronPDF's DocxToPdfRenderer to convert a Word document to PDF. Create a DocxToPdfRenderer instance, render the DOCX as a PDF, and save the resulting PDF.
IronPrint offers advantages like asynchronous printing, versatile printing options, cross-platform support, customizable print settings, seamless integration with IronQR and IronPDF, and a user-friendly API.
Yes, IronPrint supports cross-platform compatibility, making it suitable for deployment across Windows, macOS, Android, and iOS.
To install IronPrint using NuGet, open the NuGet Package Manager Console in Visual Studio and use the command: Install-Package IronPrint.
With IronPrint, you can customize print settings such as paper size, orientation, DPI, number of copies, printer name, margins, and grayscale printing.