Skip to main content

Printing and Export

  • 6 minutes to read

This document shows how you can export, print and display a print preview for the Layout Control.

Printing/Export Basics

The Layout Control provides methods to preview, print and export its contents. These methods delegate the print/export actions to the XtraPrinting Library. Thus, the print/export functionality is not available if this library cannot be found (see LayoutControl.IsPrintingAvailable).

To preview and print the Layout Control’s contents, use the following methods.

Member Description
LayoutControl.ShowPrintPreview Opens the Print Preview window for the LayoutControl with a Bars UI.
LayoutControl.ShowRibbonPrintPreview Displays the Print Preview window with a Ribbon UI.
LayoutControl.Print Prints the LayoutControl.

Using the Preview window, an end-user is able to customize the page settings (the page format, size, orientation, etc.), change a background color, export the Layout Control to various formats (PDF, HTML, etc.), etc.

The following methods allow you to export the Layout Control to various formats.

Member Description
LayoutControl.ExportToHtml Exports the control’s data to the specified stream in HTML format using the specified options.
LayoutControl.ExportToMht Exports the control’s data to the specified stream in MHT format using the specified options.
LayoutControl.ExportToPdf Exports the controls displayed within the LayoutControl to a stream in PDF format.
LayoutControl.ExportToRtf Exports the controls displayed within the LayoutControl to a stream in RTF format.
LayoutControl.ExportToText Exports the control’s data to the specified stream in Text format using the specified options.
LayoutControl.ExportToXls Exports the control’s data to the specified stream in XLS format using the specified options.
LayoutControl.ExportToXlsx Exports data to the specified stream in XLSX (MS Excel 2007) format using the specified options.

Note

Custom painting, alpha blending and color gradient features are not supported when the Layout Control is printed/exported.

Example

The following example demonstrates how to print a LayoutControl and show its Print Preivew. The LayoutControl.Print and LayoutControl.ShowPrintPreview methods are called respectively.

using DevExpress.XtraLayout;
// ...

private void ShowLayoutControlPreview(LayoutControl layout) {
    // Check whether the LayoutControl can be previewed.
    if (!layout.IsPrintingAvailable) {
        MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error");
        return;
    }

    // Open the Preview window.
    layout.ShowPrintPreview();
}

private void PrintLayoutControl(LayoutControl layout) {
    // Check whether the LayoutControl can be printed.
    if (!layout.IsPrintingAvailable) {
        MessageBox.Show("The 'DevExpress.XtraPrinting' library is not found", "Error");
        return;
    }

    // Print.
    layout.Print();
}

Default Print and Export Mode

By default, the Layout Control follows the “Flow layout” approach when arranging items in the print/export document, not the WYSIWYG approach

According to the “Flow layout” principle, layout items are arranged back-to-back, filling the page area in the optimal way. The flow of items wraps at the page’s right edge. So, if there is insufficient space in a row to accommodate an item, this item is carried over to the following row.

Items in the print/export document can occupy less space compared to their original size. For instance, a layout item with a text editor is shrunk to display the editor’s text in its entirety.

Specific compound controls (e.g., GridControl, ChartControl, SpreadsheetControl, TreeList, etc.) implement the IPrintable interface, which maintains high-quality printing/export using the DevExpress XtraPrinting Library.

When you print or export a Layout Control that contains any of these controls, the Layout Control invokes high-quality printing/export for these controls using the DevExpress Printing Library (in the old print/export mode, these controls are printed/exported as images). The IPrintable controls are printed starting from the left edge of a page, occupying the entire page width. Even if a control’s contents are partially visible on the form and vertical scrollbars are enabled, the height of the control is increased in the print/export document to print the control’s contents in their entirety.

Multiple print options provided by IPrintable controls are taken into account when the Layout Control is printed/exported.

The image below shows a print preview for a Layout Control containing several text editors and a Grid Control.

LayoutControlNewPrintingExample

Old Printing and Export (WYSIWYG)

To enable the legacy print and export mode, which follows the WYSIWYG approach, set the OptionsPrintControl.OldPrinting property to true.

In this mode, the Layout Control is printed/exported as is, keeping the arrangement of items. By default, the Layout Control is scaled to the page width. This functionality can be disabled with the OptionsPrintControl.AllowFitToPage property.

The following image demonstrates a print preview of a Layout Control containing several text editors and a Data Grid.

LayoutControlOldPrintingExample

  • Controls that are not derived from the BaseEdit class are printed as images. Their printed versions are graphical copies of display versions. For instance, if a Grid Control displays scrollbars on the form, the scrollbars will be included in the print/export output as well.
  • Text editors that are derived from the BaseEdit class are represented by their values. No border is painted when printed. Values of editors are printed as text.
  • Graphical editors that are derived from the BaseEdit class are printed as images.

Printing/Export Options

The Layout Control provides properties to customize print- and export-aware settings.

image image

image

Printing/Export Appearance

By default, a printed Layout Control uses the same appearance settings as when it is displayed on screen.

In default print/export mode, you can customize the print/export appearance settings as follows:

Note

Print appearance settings are not supported if the OptionsPrintControl.OldPrinting property is set to true.

See Also