windowsforms-7322-controls-and-libraries-printing-exporting-concepts-exporting-export-to-rtf.md
This document describes specifics of exporting a document to the RTF format (Rich Text Format).
The RtfExportOptions class provides options which define how to export the document to an RTF file. You can access these options using the report’s ExportOptions.Rtf property.
The RtfExportOptions.ExportMode property specifies how a document is exported to RTF.
Note
Not all programs that can be used to view and edit RTF files can correctly process the resulting RTF file. For instance, Microsoft® Word® displays these files correctly, while WordPad ® does not. Note that this is not due to any problem in our product - WordPad does not fully support the RTF standard.
The following table lists RTF-specific options and indicates which export modes support these options:
|
Option
|
Single File
(Continuous)
|
Single File
Page-by-Page
|
Description
| | --- | --- | --- | --- | |
FormattedTextExportOptions.ExportWatermarks
|
|
|
Specifies whether or not to include the existing text and image watermarks in a RTF file.
| |
FormattedTextExportOptions.PageRange
|
|
|
Specifies the range of pages which should be exported to RTF.
| |
FormattedTextExportOptions.KeepRowHeight
|
|
|
Specifies whether the height of table rows in a resulting document should have fixed values.
| |
FormattedTextExportOptions.EmptyFirstPageHeaderFooter
|
|
|
Defines whether the header and footer contents should be displayed on the first page of the final document.
| |
FormattedTextExportOptions.ExportPageBreaks
|
|
|
Specifies whether page breaks should be included in the resulting RTF file.
|
Take into account the following specifics, when exporting a document in the RtfExportMode.SingleFile mode:
Composite report documents created from multiple merged documents cannot be exported to the RTF format in the RtfExportMode.SingleFile (continuous) mode.
Only report controls that do not intersect with each other can be correctly exported to RTF. Otherwise, the resulting file may have a broken layout.
When exporting a document to RTF in a table-like layout, the actual height of table rows in the resulting file can be adjusted by the Microsoft® Word® rendering mechanism automatically to fit the content. This can lead to increasing the page layout and produce a result that differs from the initial document in Print Preview. To avoid this and make the row height unaffected by adding new content, set the FormattedTextExportOptions.KeepRowHeight property to true.
To locate controls’ content in native header and footer sections of the resulting RTF file, place these controls in the TopMarginBand or BottomMarginBand (not in the page footer and header).
Vector images (e.g., pictures, charts or bar codes) are always rasterized on export to RTF. You can use the PageByPageExportOptionsBase.RasterizationResolution property to define the image resolution.
The following example demonstrates how to export a report to RTF format:
using System.Diagnostics;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...
namespace ExportToRtfCS {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
// A path to export a report.
string reportPath = "c:\\Test.rtf";
// Create a report instance.
XtraReport1 report = new XtraReport1();
// Export the report to RTF.
report.ExportToRtf(reportPath);
// Show the result.
StartProcess(reportPath);
}
// Use this method if you want to automaically open
// the created RTF file in the default program.
public void StartProcess(string path) {
Process process = new Process();
try {
process.StartInfo.FileName = path;
process.Start();
process.WaitForInputIdle();
}
catch { }
}
}
}
Imports System.Diagnostics
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
' ...
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
' A path to export a report.
Dim reportPath As String = "c:\\Test.rtf"
' Create a report instance.
Dim report As New XtraReport1()
' Export the report to RTF.
report.ExportToRtf(reportPath)
' Show the result.
StartProcess(reportPath)
End Sub
' Use this method if you want to automaically open
' the created RTF file in the default program.
Public Sub StartProcess(ByVal path As String)
Dim process As New Process()
Try
process.StartInfo.FileName = path
process.Start()
process.WaitForInputIdle()
Catch
End Try
End Sub
End Class