Back to Devexpress

Print Word Documents

officefileapi-17580-word-processing-document-api-printing.md

latest5.9 KB
Original Source

Print Word Documents

  • Jan 16, 2026
  • 3 minutes to read

This document outlines the techniques used to print from the Word Processing Document API.

Use the RichEditDocumentServer.Print method to print a document with the default settings without end user interaction.

View Example

cs
// Load a document from a file.
wordProcessor.LoadDocument("Documents\\Grimm.docx", DocumentFormat.OpenXml);

// Print the document to the default printer with the default settings.
wordProcessor.Print();
vb
' Load a document from a file.
wordProcessor.LoadDocument("Documents\Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
' Print the document to the default printer with the default settings.
wordProcessor.Print()

Change Printer Settings

Pass the PrinterSettings instance as the RichEditDocumentServer.Print method parameter to specify printer options (page range, number of copies, etc.).

Warning

The Print(PrinterSettings) method oberload works only on Windows OS. The PlatformNotSupportedException is thrown on other operating systems. Use the Print method overloads with DXPrinterSettings printerSettings parameter to print on other operating systems.

View Example

csharp
using DevExpress.XtraRichEdit;
using System.Drawing.Printing;

using (var wordProcessor = new RichEditDocumentServer())
{
    wordProcessor.LoadDocument("Grimm.docx");

    PrinterSettings printerSettings = new PrinterSettings();

    // Set the document pages to print:
    printerSettings.FromPage = 2;
    printerSettings.ToPage = 3;

    // Specify the number of copies:
    printerSettings.Copies = 2;

    // Print the document: 
    wordProcessor.Print(printerSettings);
}
vb
Imports DevExpress.XtraRichEdit
Imports System.Drawing.Printing

Using wordProcessor = New RichEditDocumentServer()
    wordProcessor.LoadDocument("Grimm.docx")

    Dim printerSettings As New PrinterSettings()

    ' Set the document pages to print:
    printerSettings.FromPage = 2
    printerSettings.ToPage = 3

    ' Specify the number of copies:
    printerSettings.Copies = 2

    ' Print the document: 
    wordProcessor.Print(printerSettings)
End Using

Note

The Margins or Landscape property (accessible by the PrinterSettings.DefaultPageSettings property) do not affect the printed document’s layout. Change document section settings (accessible by the Section.Page property) to modify page layout properties before printing.

You can use the PrintingOptions class properties to specify additional print settings (to print the comment background color or update document variables before printing).

csharp
using DevExpress.XtraRichEdit;

PrintingOptions printOptions = wordProcessor.Options.Printing;
printOptions.EnableCommentBackgroundOnPrint = false;
printOptions.EnablePageBackgroundOnPrint = true;
vb
Imports DevExpress.XtraRichEdit

Dim printOptions As PrintingOptions = wordProcessor.Options.Printing
printOptions.EnableCommentBackgroundOnPrint = False
printOptions.EnablePageBackgroundOnPrint = True

Warning

The Print(PrinterSettings) method overload works only on Windows OS. The PlatformNotSupportedException is thrown on other operating systems. Use the Print method overloads with DXPrinterSettings printerSettings parameter to print on other operating systems.

Use the Print method overloads with the DXPrinterSettings printerSettings parameter to print documents in non-Windows environments ( macOS and Unix-based systems that support printing through Common UNIX Printing System (CUPS)).

Note

Install the libcups2 package separately to enable printing.

The following code sample specifies printing settings and prints the loaded document:

csharp
using DevExpress.XtraRichEdit;
using DevExpress.Drawing.Printing;

using RichEditDocumentServer wordProcessor = new RichEditDocumentServer();
wordProcessor.LoadDocument(@"C:\\Downloads\Document.docx");

DXPrinterSettings printerSettings = new DXPrinterSettings();
printerSettings.Copies = 2;
printerSettings.PageRange = "2-3";

wordProcessor.Print(printerSettings);
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.Drawing.Printing

Imports RichEditDocumentServer wordProcessor = New RichEditDocumentServer()

wordProcessor.LoadDocument("C:\\Downloads\Document.docx")

Dim printerSettings As New DXPrinterSettings()
printerSettings.Copies = 2
printerSettings.PageRange = "2-3"

wordProcessor.Print(printerSettings)

See Also

Word Processing Document API Examples