officefileapi-devexpress-dot-xtrarichedit-dot-richeditdocumentserver-cff66c02.md
Occurs before the document is saved (exported to a certain format).
Namespace : DevExpress.XtraRichEdit
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
public event BeforeExportEventHandler BeforeExport
Public Event BeforeExport As BeforeExportEventHandler
The BeforeExport event's data class is BeforeExportEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| CustomProperties | Provides access to the document’s custom properties. |
| DocumentFormat | Gets the format of the document being exported or saved. |
| Options | Provides access to the exporter options. |
You can check the Document.RequiredExportCapabilities to be sure that the chosen export format supports them.
The BeforeExport event enables you to adjust the exporter options as required.
For RTF format, you can specify the RtfDocumentExporterCompatibilityOptions.DuplicateObjectAsMetafile property to make resulting files smaller. For the HTML format, you can set the location of external content (images, css files) via the IExporterOptions.TargetUri property and specify other HtmlDocumentExporterOptions.
The code sample below shows how specify export options for different formats in the RichEditDocumentServer.BeforeExport event handler.
private void RichEditDocument_BeforeExport(object sender, BeforeExportEventArgs e)
{
if (e.DocumentFormat == DocumentFormat.PlainText)
{
//Include document fields in the exported plain text:
PlainTextDocumentExporterOptions plainTextOptions = e.Options as PlainTextDocumentExporterOptions;
plainTextOptions.ExportHiddenText = true;
plainTextOptions.FieldCodeEndMarker = ">";
plainTextOptions.FieldCodeStartMarker = "[<";
plainTextOptions.FieldResultEndMarker = "]";
}
if (e.DocumentFormat == DocumentFormat.Docx)
{
//Specify what DOCX document properties to export:
OpenXmlDocumentExporterOptions docxOptions = e.Options as OpenXmlDocumentExporterOptions;
docxOptions.ExportedDocumentProperties = DocumentPropertyNames.Title | DocumentPropertyNames.LastModifiedBy | DocumentPropertyNames.Modified;
}
if (e.DocumentFormat == DocumentFormat.Html)
{
//Specify HTML export options:
HtmlDocumentExporterOptions htmlOptions = e.Options as HtmlDocumentExporterOptions;
htmlOptions.EmbedImages = true;
htmlOptions.CssPropertiesExportType = CssPropertiesExportType.Style;
htmlOptions.UseFontSubstitution = false;
}
}
Private Sub RichEditControl_BeforeExport(ByVal sender As Object, ByVal e As BeforeExportEventArgs)
If e.DocumentFormat = DocumentFormat.PlainText Then
'Include document fields in the exported plain text:
Dim plainTextOptions As PlainTextDocumentExporterOptions = TryCast(e.Options, PlainTextDocumentExporterOptions)
plainTextOptions.ExportHiddenText = True
plainTextOptions.FieldCodeEndMarker = ">"
plainTextOptions.FieldCodeStartMarker = "[<"
plainTextOptions.FieldResultEndMarker = "]"
End If
If e.DocumentFormat = DocumentFormat.Docx Then
'Specify what DOCX document properties to export:
Dim docxOptions As OpenXmlDocumentExporterOptions = TryCast(e.Options, OpenXmlDocumentExporterOptions)
docxOptions.ExportedDocumentProperties = DocumentPropertyNames.Title Or DocumentPropertyNames.LastModifiedBy Or DocumentPropertyNames.Modified
End If
If e.DocumentFormat = DocumentFormat.Html Then
'Specify HTML export options:
Dim htmlOptions As HtmlDocumentExporterOptions = TryCast(e.Options, HtmlDocumentExporterOptions)
htmlOptions.EmbedImages = True
htmlOptions.CssPropertiesExportType = CssPropertiesExportType.Style
htmlOptions.UseFontSubstitution = False
End If
End Sub
The following code snippets (auto-collected from DevExpress Examples) contain references to the BeforeExport event.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
word-document-api-send-mail-merge-document-as-email/CS/RichEditMailMessageExporter.cs#L34
server.BeforeExport += OnBeforeExport;
string htmlBody = server.Document.GetHtmlText(server.Document.Range, this);
word-document-api-examples/CS/CodeExamples/ExportActions.cs#L142
// Handle the Before Export event.
wordProcessor.BeforeExport += (s, e) =>
{
word-document-api-send-mail-merge-document-as-email/VB/RichEditMailMessageExporter.vb#L32
If Not Directory.Exists(tempFiles) Then Directory.CreateDirectory(tempFiles)
AddHandler server.BeforeExport, AddressOf OnBeforeExport
Dim htmlBody As String = server.Document.GetHtmlText(server.Document.Range, Me)
word-document-api-examples/VB/CodeExamples/ExportActions.vb#L127
' Handle the Before Export event.
AddHandler wordProcessor.BeforeExport,
Sub(s, e)
See Also
RichEditDocumentServer.SaveDocument*