CompatibilityOptions class

CompatibilityOptions class

Contains compatibility options (that is, the user preferences entered on the Compatibility tab of the Options dialog in Microsoft Word). To learn more, visit the Detect File Format and Check Format Compatibility documentation article.

Properties

NameDescription
adjust_line_height_in_tableAdd Document Grid Line Pitch To Lines in Table Cells.
align_tables_row_by_rowAlign Table Rows Independently.
allow_space_of_same_style_in_tableAllow Contextual Spacing of Paragraphs in Tables.
apply_breaking_rulesUse Legacy Ethiopic and Amharic Line Breaking Rules.
auto_space_like_word95Emulate Word 95 Full-Width Character Spacing.
autofit_to_first_fixed_width_cellAllow Table Columns To Exceed Preferred Widths of Constituent Cells.
balance_single_byte_double_byte_widthBalance Single Byte and Double Byte Characters.
cached_col_balanceUse Cached Paragraph Information for Column Balancing.
conv_mail_merge_escTreat Backslash Quotation Delimiter as Two Quotation Marks.
disable_open_type_font_formatting_featuresSpecifies to disable OpenType font formatting features.
display_hangul_fixed_widthAlways Use Fixed Width for Hangul Characters.
do_not_autofit_constrained_tablesDo Not AutoFit Tables To Fit Next To Wrapped Objects.
do_not_break_constrained_forced_tableDon’t Break Table Rows Around Floating Tables.
do_not_break_wrapped_tablesDo Not Allow Floating Tables To Break Across Pages.
do_not_expand_shift_returnDon’t Justify Lines Ending in Soft Line Break.
do_not_leave_backslash_aloneConvert Backslash To Yen Sign When Entered.
do_not_snap_to_grid_in_cellDo Not Snap to Document Grid in Table Cells with Objects.
do_not_suppress_indentationDo Not Ignore Floating Objects When Calculating Paragraph Indentation.
do_not_suppress_paragraph_bordersDo Not Suppress Paragraph Borders Next To Frames.
do_not_use_east_asian_break_rulesDo Not Compress Compressible Characters When Using Document Grid.
do_not_use_html_paragraph_auto_spacingUse Fixed Paragraph Spacing for HTML Auto Setting.
do_not_use_indent_as_numbering_tab_stopIgnore Hanging Indent When Creating Tab Stop After Numbering.
do_not_vert_align_cell_with_spDon’t Vertically Align Cells Containing Floating Objects.
do_not_vert_align_in_txbxIgnore Vertical Alignment in Textboxes.
do_not_wrap_text_with_punctDo Not Allow Hanging Punctuation With Character Grid.
footnote_layout_like_ww8Emulate Word 6.x/95/97 Footnote Placement.
forget_last_tab_alignmentIgnore Width of Last Tab Stop When Aligning Paragraph If It Is Not Left Aligned.
grow_autofitAllow Tables to AutoFit Into Page Margins.
layout_raw_table_widthIgnore Space Before Table When Deciding If Table Should Wrap Floating Object.
layout_table_rows_apartAllow Table Rows to Wrap Inline Objects Independently.
line_wrap_like_word6Emulate Word 6.0 Line Wrapping for East Asian Text.
mw_small_capsEmulate Word 5.x for the Macintosh Small Caps Formatting.
no_column_balanceDo Not Balance Text Columns within a Section.
no_extra_line_spacingDo Not Center Content on Lines With Exact Line Height.
no_leadingDo Not Add Leading Between Lines of Text.
no_space_raise_lowerDo Not Increase Line Height for Raised/Lowered Text.
no_tab_hang_indDo Not Create Custom Tab Stop for Hanging Indent.
override_table_style_font_size_and_justificationSpecifies how the style hierarchy of the document is evaluated.
print_body_text_before_headerPrint Body Text before Header/Footer Contents.
print_col_blackPrint Colors as Black And White without Dithering.
select_fld_with_first_or_last_charSelect Field When First or Last Character Is Selected.
shape_layout_like_ww8Emulate Word 97 Text Wrapping Around Floating Objects.
show_breaks_in_framesDisplay Page/Column Breaks Present in Frames.
space_for_ulAdd Additional Space Below Baseline For Underlined East Asian Text.
spacing_in_whole_pointsOnly Expand/Condense Text By Whole Points.
split_pg_break_and_para_markAlways Move Paragraph Mark to Page after a Page Break.
sub_font_by_sizeIncrease Priority Of Font Size During Font Substitution.
suppress_bottom_spacingIgnore Exact Line Height for Last Line on Page.
suppress_sp_bf_after_pg_brkDo Not Use Space Before On First Line After a Page Break.
suppress_spacing_at_top_of_pageIgnore Minimum Line Height for First Line on Page.
suppress_top_spacingIgnore Minimum and Exact Line Height for First Line on Page.
suppress_top_spacing_wpEmulate WordPerfect 5.x Line Spacing.
swap_borders_facing_pgsSwap Paragraph Borders on Odd Numbered Pages.
swap_inside_and_outside_for_mirror_indents_and_relative_positioningSpecifies to swap inside and outside for mirror indents and relative positioning.
transparent_metafilesSpecifies not to blank the area behind metafile pictures.
truncate_font_heights_like_wp6Emulate WordPerfect 6.x Font Height Calculation.
ui_compat_97_to_2003True to disable UI functionality which is not compatible with Word97-2003. Default value is False.
ul_trail_spaceUnderline All Trailing Spaces.
underline_tab_in_num_listUnderline Following Character Following Numbering.
use_alt_kinsoku_line_break_rulesUse Alternate Set of East Asian Line Breaking Rules.
use_ansi_kerning_pairsUse ANSI Kerning Pairs from Fonts.
use_fe_layoutDo Not Bypass East Asian/Complex Script Layout Code.
use_normal_style_for_listDo Not Automatically Apply List Paragraph Style To Bulleted/Numbered Text.
use_printer_metricsUse Printer Metrics To Display Documents.
use_single_borderfor_contiguous_cellsUse Simplified Rules For Table Border Conflicts.
use_word2002_table_style_rulesEmulate Word 2002 Table Style Rules.
use_word2010_table_style_rulesSpecifies to use Word2010 table style rules.
use_word97_line_break_rulesEmulate Word 97 East Asian Line Breaking.
wp_justificationEmulate WordPerfect 6.x Paragraph Justification.
wp_space_widthSpecifies whether to set the width of a space as is done in WordPerfect 5.x.
wrap_trail_spacesLine Wrap Trailing Spaces.

Methods

NameDescription
optimize_for(version)Allows to optimize the document contents as well as default Aspose.Words behavior to a particular versions of MS Word.

Examples

Shows how to optimize the document for different versions of Microsoft Word.

def test_optimize_for(self):

    doc = aw.Document()

    # This object contains an extensive list of flags unique to each document
    # that allow us to facilitate backward compatibility with older versions of Microsoft Word.
    options = doc.compatibility_options

    # Print the default settings for a blank document.
    print("\nDefault optimization settings:")
    ExCompatibilityOptions.print_compatibility_options(options)

    # We can access these settings in Microsoft Word via "File" -> "Options" -> "Advanced" -> "Compatibility options for...".
    doc.save(ARTIFACTS_DIR + "CompatibilityOptions.optimize_for.default_settings.docx")

    # We can use the OptimizeFor method to ensure optimal compatibility with a specific Microsoft Word version.
    doc.compatibility_options.optimize_for(aw.settings.MsWordVersion.WORD2010)
    print("\nOptimized for Word 2010:")
    ExCompatibilityOptions.print_compatibility_options(options)

    doc.compatibility_options.optimize_for(aw.settings.MsWordVersion.WORD2000)
    print("\nOptimized for Word 2000:")
    ExCompatibilityOptions.print_compatibility_options(options)

@staticmethod
def print_compatibility_options(options: aw.settings.CompatibilityOptions):
    """Groups all flags in a document's compatibility options object by state, then prints each group."""

    for enabled in (True, False):
        print("\tEnabled options:" if enabled else "\tDisabled options:")
        for opt in dir(options):
            if not opt.startswith('__') and not callable(getattr(options, opt)) and getattr(options, opt) == enabled:
                print(f"\t\t{opt}")

Shows how to set an OOXML compliance specification for a saved document to adhere to.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

# If we configure compatibility options to comply with Microsoft Word 2003,
# inserting an image will define its shape using VML.
doc.compatibility_options.optimize_for(aw.settings.MsWordVersion.WORD2003)
builder.insert_image(IMAGE_DIR + "Transparent background logo.png")

self.assertEqual(aw.drawing.ShapeMarkupLanguage.VML, doc.get_child(aw.NodeType.SHAPE, 0, True).as_shape().markup_language)

# The "ISO/IEC 29500:2008" OOXML standard does not support VML shapes.
# If we set the "compliance" property of the SaveOptions object to "OoxmlCompliance.ISO29500_2008_STRICT",
# any document we save while passing this object will have to follow that standard.
save_options = aw.saving.OoxmlSaveOptions()
save_options.compliance = aw.saving.OoxmlCompliance.ISO29500_2008_STRICT
save_options.save_format = aw.SaveFormat.DOCX

doc.save(ARTIFACTS_DIR + "OoxmlSaveOptions.iso29500_strict.docx", save_options)

# Our saved document defines the shape using DML to adhere to the "ISO/IEC 29500:2008" OOXML standard.
doc = aw.Document(ARTIFACTS_DIR + "OoxmlSaveOptions.iso29500_strict.docx")

self.assertEqual(aw.drawing.ShapeMarkupLanguage.DML, doc.get_child(aw.NodeType.SHAPE, 0, True).as_shape().markup_language)

Shows how to vertically align the text contents of a text box.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

shape = builder.insert_shape(aw.drawing.ShapeType.TEXT_BOX, 200, 200)

# Set the "vertical_anchor" property to "TextBoxAnchor.TOP" to
# align the text in this text box with the top side of the shape.
# Set the "vertical_anchor" property to "TextBoxAnchor.MIDDLE" to
# align the text in this text box to the center of the shape.
# Set the "vertical_anchor" property to "TextBoxAnchor.BOTTOM" to
# align the text in this text box to the bottom of the shape.
shape.text_box.vertical_anchor = vertical_anchor

builder.move_to(shape.first_paragraph)
builder.write("Hello world!")

# The vertical aligning of text inside text boxes is available from Microsoft Word 2007 onwards.
doc.compatibility_options.optimize_for(aw.settings.MsWordVersion.WORD2007)
doc.save(ARTIFACTS_DIR + "Shape.vertical_anchor.docx")

See Also