DocumentCompatibilityOptions Property

Provides access to document compatibility options (that is, the user preferences entered on the Compatibility tab of the Options dialog in Word).

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.7.0

Syntax

public CompatibilityOptions CompatibilityOptions { get; }

Property Value

Type: CompatibilityOptions

Examples

Shows how to optimize document for different word versions.
public void OptimizeFor()
{
    // Create a blank document and get its CompatibilityOptions object
    Document doc = new Document();
    CompatibilityOptions options = doc.CompatibilityOptions;

    // By default, the CompatibilityOptions will contain the set of values printed below
    Console.WriteLine("\nDefault optimization settings:");
    PrintCompatibilityOptions(options);

    // These attributes can be accessed in the output document via File > Options > Advanced > Compatibility for...
    doc.Save(ArtifactsDir + "CompatibilityOptions.OptimizeFor.DefaultSettings.docx");

    // We can use the OptimizeFor method to set these values automatically
    // for maximum compatibility with some Microsoft Word versions
    doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2010);
    Console.WriteLine("\nOptimized for Word 2010:");
    PrintCompatibilityOptions(options);

    doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2000);
    Console.WriteLine("\nOptimized for Word 2000:");
    PrintCompatibilityOptions(options);
}

/// <summary>
/// Prints all options of a CompatibilityOptions object and indicates whether they are enabled or disabled
/// </summary>
private static void PrintCompatibilityOptions(CompatibilityOptions options)
{
    for (int i = 1; i >= 0; i--)
    {
        Console.WriteLine(Convert.ToBoolean(i) ? "\tEnabled options:" : "\tDisabled options:");
        SortedSet<string> optionNames = new SortedSet<string>();

        foreach (System.ComponentModel.PropertyDescriptor descriptor in System.ComponentModel.TypeDescriptor.GetProperties(options))
        {
            if (descriptor.PropertyType == Type.GetType("System.Boolean") && i == Convert.ToInt32(descriptor.GetValue(options)))
            {
                optionNames.Add(descriptor.Name);
            }
        }

        foreach (string s in optionNames)
        {
            Console.WriteLine($"\t\t{s}");
        }
    }
}

See Also