Export to RTF

  • 7 minutes to read

This document describes how to export a report document to RTF format.

You can export a report from the Report Designer's Preview and the Document Viewer on all supported platforms (WinForms, WPF, ASP.NET Web Forms, ASP.NET MVC, and ASP.NET Core). To do this, expand the Export Document drop-down list and select RTF File. Specify export options in the invoked dialog, and click OK.

To export a report document to RTF format in code, use one of the following approaches:

  • Export a Report

    Call an XtraReport.ExportToRtf overloaded method to export a report. To export a report asynchronously in a separate task, call an XtraReport.ExportToRtfAsync overloaded method instead. To specify export options, create a RtfExportOptions class instance and pass this instance to the invoked method, or use XtraReport's ExportOptions.Rtf property.

    using System;
    using DevExpress.XtraPrinting;
    using DevExpress.XtraReports.UI;
    // ...
    XtraReport report = new XtraReport() {
        Name = "HelloWorld",
        Bands = {
            new DetailBand(){
                Controls={
                    new XRLabel(){
                        Text="Hello World!"
                    }
                }
            }
        }
    };
    // rtfExportFile specifies the exported file's name and path. The user's Downloads folder is used as the default path.
    string rtfExportFile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads\" + report.Name + ".rtf";
    // Specify export options to export the report.
    // Uncomment the lines below to specify export options in an RtfExportOptions class instance.
    // RtfExportOptions RtfExportOptions = new RtfExportOptions();
    // RtfExportOptions.ExportMode = RtfExportMode.SingleFile;
    // report.ExportToRtf(rtfExportFile, RtfExportOptions);
    
    // Comment the lines below if you specified export options in an RtfExportOptions class instance above.
    report.ExportOptions.Rtf.ExportMode = RtfExportMode.SingleFile;
    report.ExportToRtf(rtfExportFile);
    
  • Export a Document

    Call a PrintingSystem.ExportToRtf overloaded method to export a document. To specify export options, create a RtfExportOptions class instance and pass this instance to the invoked method, or use PrintingSystem's ExportOptions.Rtf property.

    using System;
    using DevExpress.XtraPrinting;
    using DevExpress.XtraReports.UI;
    // ...
    XtraReport report = new XtraReport() {
        Name = "HelloWorld",
        Bands = {
            new DetailBand(){
                Controls={
                    new XRLabel(){
                        Text="Hello World!"
                    }
                }
            }
        }
    };
    // Create a document from the report.
    report.CreateDocument();
    // rtfExportFile specifies the exported file's name and path. The user's Downloads folder is used as the default path.
    string rtfExportFile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads\" + report.Name + ".rtf";
    // Specify export options and export the document.
    // Uncomment the lines below to specify export options in an RtfExportOptions class instance.
    // RtfExportOptions RtfExportOptions = new RtfExportOptions();
    // RtfExportOptions.ExportMode = RtfExportMode.SingleFile;
    // report.PrintingSystem.ExportToRtf(rtfExportFile, RtfExportOptions);
    
    // Comment the lines below if you specified export options in an RtfExportOptions class instance above.
    report.PrintingSystem.ExportOptions.Rtf.ExportMode = RtfExportMode.SingleFile;
    report.PrintingSystem.ExportToRtf(rtfExportFile);
    
  • Export a Control

    Call a PrintingLink.ExportToRtf overloaded method to export a control. To specify export options, create a RtfExportOptions class instance and pass this instance to the invoked method.

    using System;
    using DevExpress.XtraPrinting;
    using DevExpress.XtraReports.UI;
    // ...
    DevExpress.XtraCharts.ChartControl chart = new DevExpress.XtraCharts.ChartControl() {
        Name = "IncomeByQuarter",
        Series = {
            new DevExpress.XtraCharts.Series("2019", DevExpress.XtraCharts.ViewType.Bar)
        }
    };
    // Create a printing link.
    PrintingSystem printingSystem = new PrintingSystem();
    PrintableComponentLink link = new PrintableComponentLink();
    printingSystem.Links.Add(link);
    link.Component = chart;
    // rtfExportFile specifies the exported file's name and path. The user's Downloads folder is used as the default path.
    string rtfExportFile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + @"\Downloads\" + chart.Name + ".rtf";
    // Specify export options and export the control.
    RtfExportOptions RtfExportOptions = new RtfExportOptions();
    RtfExportOptions.ExportMode = RtfExportMode.SingleFile;
    link.ExportToRtf(rtfExportFile, RtfExportOptions);
    

The RtfExportOptions class exposes options for report export to to RTF. Use the report's ExportOptions.Rtf property to access these options.

The RtfExportOptions.ExportMode property specifies how a document is exported to RTF:

  • SingleFilePageByPage

    The export follows the WYSIWYG paradigm: the report's page headers and footers, and top and bottom margins appear on every page of the resulting document as they appear in the report's Print Preview. Elements residing in your report are treated as frames in the resulting file.

  • SingleFile

    A multi-page report is converted into a single document with a table-like layout: the report's page headers and footers are repeated only once - at the beginning and end of the resulting document.

NOTE

Not all programs that can be used to view and edit RTF files can correctly process the RTF export files. For instance, Microsoft® Word® displays these files correctly but WordPad® does not. This is because WordPad does not fully support the RTF standard.

The following table lists RTF-specific options and export modes where these options are supported:

Option

Single File

(Continuous)

Single File

Page-by-Page

Description

FormattedTextExportOptions.ExportWatermarks

Icon-yes

Icon-yes

Specifies whetherto include the text and image watermarks in the RTF file.

FormattedTextExportOptions.PageRange

Icon-no

Icon-yes

Specifies the page range to export to RTF.

FormattedTextExportOptions.KeepRowHeight

Icon-yes

Icon-no

Specifies whether the table row heights should be fixed in the export document.

FormattedTextExportOptions.EmptyFirstPageHeaderFooter

Icon-yes

Icon-no

Defines whether to display the header and footer contents on the exported document's first page.

FormattedTextExportOptions.ExportPageBreaks

Icon-yes

Icon-no

Specifies whether to include page breaks in the exported file.

The following specifics apply to documents exported in the RtfExportMode.SingleFile mode:

  • You cannot export reports merged page by page in the Single File export mode. As a workaround:

    • Use subreports to merge multiple reports into a single document.
    • Export all reports to separate files and join these files in a single file.
  • To ensure that report controls are exported correctly, they should not intersect. Otherwise, the file layout can be corrupted.

    Overlapped controls are highlighted in reports. Users can move the mouse pointer over these controls to see what needs to be fixed.

    ShowExportWarnings

    Use a report's HasExportWarningControls collection to check if there are controls that have export warnings.

    Disable a report's DesignerOptions.ShowExportWarnings property to remove highlights on overlapped controls.

  • When a document is exported to RTF in a table-like layout, Microsoft® Word® can set table row heights to fit content. As a result, the exported document can differ from the initial document in Print Preview. To avoid this effect, enable the FormattedTextExportOptions.KeepRowHeight property.

    If you disable this property or leave it at the default value, row heights are not fixed. A new line of text added to a cell's content increases the row height.

    KeepRowHeight = false KeepRowHeight = true
    RtfExportOptions-KeepRowHeight-false RtfExportOptions-KeepRowHeight
  • To locate controls' content in the export file's native header and footer sections, place these controls in the TopMarginBand or BottomMarginBand rather than in the page footer and header.

  • If a report uses a CachedReportSource, changes made in Preview are not included in the exported file.

Vector images (for instance, pictures, charts, or bar codes) are rasterized in the exported file. Use the PageByPageExportOptionsBase.RasterizationResolution property to specify the image resolution.