Save Word with OOXML compliance

When you save a Word document in its original format, you can set its OOXML compliance level through save_options.wordprocessing_save_options.ooxml_compliance (WordprocessingSaveOptions). The values come from WordProcessingComplianceLevel: ECMA, TRANSITIONAL or STRICT.

Without it, the compliance level of the original document is kept. A Strict document can be saved as Transitional, but not as Ecma.

The option applies to the OOXML Word formats: DOCX, DOCM, DOTX and DOTM. Set rasterize_to_pdf to False, so that the document is saved in its Word format instead of as a rasterized PDF.

from groupdocs.redaction import Redactor
from groupdocs.redaction.options import SaveOptions, WordProcessingComplianceLevel
from groupdocs.redaction.redactions import ExactPhraseRedaction, ReplacementOptions

def save_word_with_ooxml_compliance():
    with Redactor("./sample.docx") as redactor:
        redactor.apply(ExactPhraseRedaction("Emily Johnson", ReplacementOptions("[personal]")))

        options = SaveOptions()
        options.add_suffix = True
        options.rasterize_to_pdf = False  # keep the Word format
        options.redacted_file_suffix = "Strict"
        # Without this line the original document's compliance level is kept
        options.wordprocessing_save_options.ooxml_compliance = WordProcessingComplianceLevel.STRICT

        result_path = redactor.save(options)
        print("Output saved to " + result_path)

if __name__ == "__main__":
    save_word_with_ooxml_compliance()
sample.docx is the sample file used in this example. Click here to download it.
Binary file (DOCX, 42 KB)

Download full output