Back to Devexpress

RtfDocumentExporterCompatibilityOptions.DuplicateObjectAsMetafile Property

officefileapi-devexpress-dot-xtrarichedit-dot-export-dot-rtfdocumentexportercompatibilityoptions.md

latest8.0 KB
Original Source

RtfDocumentExporterCompatibilityOptions.DuplicateObjectAsMetafile Property

Gets or sets whether inline objects are saved in the RTF file twice - as an object and as metafile content.

Namespace : DevExpress.XtraRichEdit.Export

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
public bool DuplicateObjectAsMetafile { get; set; }
vb
Public Property DuplicateObjectAsMetafile As Boolean

Property Value

TypeDescription
Boolean

true to duplicate objects as metafiles when saving; otherwise, false. Default value is false.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to DuplicateObjectAsMetafile
RtfDocumentExporterOptions

.Compatibility .DuplicateObjectAsMetafile

|

Remarks

RTF specification allows RTF writers to save embedded pictures two times - in the native format and as a metafile, so if the application is unable to load the original object, it can skip it, and display the graphics metafile instead. Included metafiles may result in “bloated” RTF files.

By default, the pictures are saved only in original format. To enable dual saving of a picture (thus increasing the file size), you can handle the BeforeExport event and set the DuplicateObjectAsMetafile property to true. The following code snippet illustrates this technique.

View Example

csharp
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.Export;
using DevExpress.XtraRichEdit.Services;
private void btnSaveToFile_Click(object sender, EventArgs e) {
    richEditControl1.SaveDocument("SavedDocument.rtf", DocumentFormat.Rtf);
    System.IO.FileInfo fi = new System.IO.FileInfo("SavedDocument.rtf");
    string msg = String.Format("The size of the file is {0:#,#} bytes.", fi.Length.ToString("#,#"));
    MessageBox.Show(msg);
}

private void richEditControl1_BeforeExport(object sender, DevExpress.XtraRichEdit.BeforeExportEventArgs e) {
    DocumentExportCapabilities checkDocument = richEditControl1.Document.RequiredExportCapabilities;
    if((e.DocumentFormat == DocumentFormat.Rtf) && checkDocument.InlinePictures ) {
        DialogResult reduceFileSize = MessageBox.Show("This document contains inline pictures.\n" +
        "You can embed the same picture in two different types (original and Windows Metafile) for better compatibility" +
        " although it increases the file size. By default a picture is saved in original format only.\n" +
        "Enable dual picture format in a saved file?",
        "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

        RtfDocumentExporterOptions options = e.Options as RtfDocumentExporterOptions;
        if(options != null) {
            switch (reduceFileSize) {
            case DialogResult.Yes:
                    options.Compatibility.DuplicateObjectAsMetafile = true;
                    break;
            case System.Windows.Forms.DialogResult.No:
                    options.Compatibility.DuplicateObjectAsMetafile = false;
                    break;
            }
        }
    }
}
vb
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.Export
Imports DevExpress.XtraRichEdit.Services
Private Sub btnSaveToFile_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSaveToFile.Click
    richEditControl1.SaveDocument("SavedDocument.rtf", DocumentFormat.Rtf)
    Dim fi As New System.IO.FileInfo("SavedDocument.rtf")
    Dim msg As String = String.Format("The size of the file is {0:#,#} bytes.", fi.Length.ToString("#,#"))
    MessageBox.Show(msg)
End Sub

Private Sub richEditControl1_BeforeExport(ByVal sender As Object, ByVal e As DevExpress.XtraRichEdit.BeforeExportEventArgs) Handles richEditControl1.BeforeExport
    Dim checkDocument As DocumentExportCapabilities = richEditControl1.Document.RequiredExportCapabilities
    If (e.DocumentFormat = DocumentFormat.Rtf) AndAlso checkDocument.InlinePictures Then
        Dim reduceFileSize As DialogResult = MessageBox.Show("This document contains inline pictures." & Constants.vbLf & "You can embed the same picture in two different types (original and Windows Metafile) for better compatibility" & " although it increases the file size. By default a picture is saved in original format only." & Constants.vbLf & "Enable dual picture format in a saved file?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)

        Dim options As RtfDocumentExporterOptions = TryCast(e.Options, RtfDocumentExporterOptions)
        If options IsNot Nothing Then
            Select Case reduceFileSize
            Case System.Windows.Forms.DialogResult.Yes
                    options.Compatibility.DuplicateObjectAsMetafile = True
            Case System.Windows.Forms.DialogResult.No
                    options.Compatibility.DuplicateObjectAsMetafile = False
            End Select
        End If
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the DuplicateObjectAsMetafile property.

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.

winforms-richedit-save-a-document/CS/SaveDocument/Form1.cs#L52

csharp
case DialogResult.Yes:
        options.Compatibility.DuplicateObjectAsMetafile = true;
        break;

word-document-api-automatic-document-conversion-on-web-server/CS/Program.cs#L94

csharp
{
    server.Options.Export.Rtf.Compatibility.DuplicateObjectAsMetafile = false;
}

winforms-richedit-save-a-document/VB/SaveDocument/Form1.vb#L44

vb
Case DialogResult.Yes
    options.Compatibility.DuplicateObjectAsMetafile = True
Case DialogResult.No

word-document-api-automatic-document-conversion-on-web-server/VB/Program.vb#L83

vb
If destFormat = DocumentFormat.Rtf Then
    server.Options.Export.Rtf.Compatibility.DuplicateObjectAsMetafile = False
End If

See Also

RtfDocumentExporterCompatibilityOptions Class

RtfDocumentExporterCompatibilityOptions Members

DevExpress.XtraRichEdit.Export Namespace