In this step by step tutorial, we’ll elaborate how to print Word document in C# without interop and without automation. We’ll use Windows Forms application to print Word DOCX in C# using a printer dialog.
Steps to Print Word Document in C# Without Interop
- Install Aspose.Words for .NET package from NuGet.org
- Add reference to Aspose.Words and Aspose.Words.Rendering namespaces
- Set license of Aspose.Words for .NET using SetLicense method
- Create a new Document object and load DOCX document
- Create a new PrintDialog object and set printer dialog properties
- Create PrintPreviewDialog object and set AsposeWordsPrintDocument object and other properties
- Attach event to activate the printer dialog
- Finally, show the printer dialog to the user
In the above steps, we’re loading Word document into Document object, setting properties of the printer dialog and then passing the document to the created printer dialog instance. These steps help print Word document in C# using a windows printer dialog. We’ll add a separate how-to topic, to show how to print Word document without a printer dialog.
Code to Print Word Document in C# Without Automation
The above code in C# print Word document without opening the DOCX or DOC file itself. It sets the properties of the print dialog along with passing the document itself and then let the user print the document.