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
Name | Description |
---|---|
adjust_line_height_in_table | Add Document Grid Line Pitch To Lines in Table Cells. |
align_tables_row_by_row | Align Table Rows Independently. |
allow_space_of_same_style_in_table | Allow Contextual Spacing of Paragraphs in Tables. |
apply_breaking_rules | Use Legacy Ethiopic and Amharic Line Breaking Rules. |
auto_space_like_word95 | Emulate Word 95 Full-Width Character Spacing. |
autofit_to_first_fixed_width_cell | Allow Table Columns To Exceed Preferred Widths of Constituent Cells. |
balance_single_byte_double_byte_width | Balance Single Byte and Double Byte Characters. |
cached_col_balance | Use Cached Paragraph Information for Column Balancing. |
conv_mail_merge_esc | Treat Backslash Quotation Delimiter as Two Quotation Marks. |
disable_open_type_font_formatting_features | Specifies to disable OpenType font formatting features. |
display_hangul_fixed_width | Always Use Fixed Width for Hangul Characters. |
do_not_autofit_constrained_tables | Do Not AutoFit Tables To Fit Next To Wrapped Objects. |
do_not_break_constrained_forced_table | Don’t Break Table Rows Around Floating Tables. |
do_not_break_wrapped_tables | Do Not Allow Floating Tables To Break Across Pages. |
do_not_expand_shift_return | Don’t Justify Lines Ending in Soft Line Break. |
do_not_leave_backslash_alone | Convert Backslash To Yen Sign When Entered. |
do_not_snap_to_grid_in_cell | Do Not Snap to Document Grid in Table Cells with Objects. |
do_not_suppress_indentation | Do Not Ignore Floating Objects When Calculating Paragraph Indentation. |
do_not_suppress_paragraph_borders | Do Not Suppress Paragraph Borders Next To Frames. |
do_not_use_east_asian_break_rules | Do Not Compress Compressible Characters When Using Document Grid. |
do_not_use_html_paragraph_auto_spacing | Use Fixed Paragraph Spacing for HTML Auto Setting. |
do_not_use_indent_as_numbering_tab_stop | Ignore Hanging Indent When Creating Tab Stop After Numbering. |
do_not_vert_align_cell_with_sp | Don’t Vertically Align Cells Containing Floating Objects. |
do_not_vert_align_in_txbx | Ignore Vertical Alignment in Textboxes. |
do_not_wrap_text_with_punct | Do Not Allow Hanging Punctuation With Character Grid. |
footnote_layout_like_ww8 | Emulate Word 6.x/95/97 Footnote Placement. |
forget_last_tab_alignment | Ignore Width of Last Tab Stop When Aligning Paragraph If It Is Not Left Aligned. |
grow_autofit | Allow Tables to AutoFit Into Page Margins. |
layout_raw_table_width | Ignore Space Before Table When Deciding If Table Should Wrap Floating Object. |
layout_table_rows_apart | Allow Table Rows to Wrap Inline Objects Independently. |
line_wrap_like_word6 | Emulate Word 6.0 Line Wrapping for East Asian Text. |
mw_small_caps | Emulate Word 5.x for the Macintosh Small Caps Formatting. |
no_column_balance | Do Not Balance Text Columns within a Section. |
no_extra_line_spacing | Do Not Center Content on Lines With Exact Line Height. |
no_leading | Do Not Add Leading Between Lines of Text. |
no_space_raise_lower | Do Not Increase Line Height for Raised/Lowered Text. |
no_tab_hang_ind | Do Not Create Custom Tab Stop for Hanging Indent. |
override_table_style_font_size_and_justification | Specifies how the style hierarchy of the document is evaluated. |
print_body_text_before_header | Print Body Text before Header/Footer Contents. |
print_col_black | Print Colors as Black And White without Dithering. |
select_fld_with_first_or_last_char | Select Field When First or Last Character Is Selected. |
shape_layout_like_ww8 | Emulate Word 97 Text Wrapping Around Floating Objects. |
show_breaks_in_frames | Display Page/Column Breaks Present in Frames. |
space_for_ul | Add Additional Space Below Baseline For Underlined East Asian Text. |
spacing_in_whole_points | Only Expand/Condense Text By Whole Points. |
split_pg_break_and_para_mark | Always Move Paragraph Mark to Page after a Page Break. |
sub_font_by_size | Increase Priority Of Font Size During Font Substitution. |
suppress_bottom_spacing | Ignore Exact Line Height for Last Line on Page. |
suppress_sp_bf_after_pg_brk | Do Not Use Space Before On First Line After a Page Break. |
suppress_spacing_at_top_of_page | Ignore Minimum Line Height for First Line on Page. |
suppress_top_spacing | Ignore Minimum and Exact Line Height for First Line on Page. |
suppress_top_spacing_wp | Emulate WordPerfect 5.x Line Spacing. |
swap_borders_facing_pgs | Swap Paragraph Borders on Odd Numbered Pages. |
swap_inside_and_outside_for_mirror_indents_and_relative_positioning | Specifies to swap inside and outside for mirror indents and relative positioning. |
transparent_metafiles | Specifies not to blank the area behind metafile pictures. |
truncate_font_heights_like_wp6 | Emulate WordPerfect 6.x Font Height Calculation. |
ui_compat_97_to_2003 | True to disable UI functionality which is not compatible with Word97-2003. Default value is False . |
ul_trail_space | Underline All Trailing Spaces. |
underline_tab_in_num_list | Underline Following Character Following Numbering. |
use_alt_kinsoku_line_break_rules | Use Alternate Set of East Asian Line Breaking Rules. |
use_ansi_kerning_pairs | Use ANSI Kerning Pairs from Fonts. |
use_fe_layout | Do Not Bypass East Asian/Complex Script Layout Code. |
use_normal_style_for_list | Do Not Automatically Apply List Paragraph Style To Bulleted/Numbered Text. |
use_printer_metrics | Use Printer Metrics To Display Documents. |
use_single_borderfor_contiguous_cells | Use Simplified Rules For Table Border Conflicts. |
use_word2002_table_style_rules | Emulate Word 2002 Table Style Rules. |
use_word2010_table_style_rules | Specifies to use Word2010 table style rules. |
use_word97_line_break_rules | Emulate Word 97 East Asian Line Breaking. |
wp_justification | Emulate WordPerfect 6.x Paragraph Justification. |
wp_space_width | Specifies whether to set the width of a space as is done in WordPerfect 5.x. |
wrap_trail_spaces | Line Wrap Trailing Spaces. |
Methods
Name | Description |
---|---|
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 optimize_for():
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:')
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:')
print_compatibility_options(options)
doc.compatibility_options.optimize_for(aw.settings.MsWordVersion.WORD2000)
print('\nOptimized for Word 2000:')
print_compatibility_options(options)
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=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(file_name=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(file_name=ARTIFACTS_DIR + 'OoxmlSaveOptions.Iso29500Strict.docx', save_options=save_options)
# Our saved document defines the shape using DML to adhere to the "ISO/IEC 29500:2008" OOXML standard.
doc = aw.Document(file_name=ARTIFACTS_DIR + 'OoxmlSaveOptions.Iso29500Strict.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=doc)
shape = builder.insert_shape(shape_type=aw.drawing.ShapeType.TEXT_BOX, width=200, height=200)
# Set the "VerticalAnchor" property to "TextBoxAnchor.Top" to
# align the text in this text box with the top side of the shape.
# Set the "VerticalAnchor" property to "TextBoxAnchor.Middle" to
# align the text in this text box to the center of the shape.
# Set the "VerticalAnchor" 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(file_name=ARTIFACTS_DIR + 'Shape.VerticalAnchor.docx')
See Also
- module aspose.words.settings
- class Document
- property Document.compatibility_options