The following example demonstrates how to save the redacted document, replacing an original file:
fromgroupdocs.redactionimportRedactor,RedactionStatusfromgroupdocs.redaction.optionsimportSaveOptionsfromgroupdocs.redaction.redactionsimportExactPhraseRedaction,ReplacementOptionsfromgroupdocs.pydrawingimportColordefsave_overwriting_original_file():# Define the color of redactioncolor=Color.from_argb(255,220,20,60)# Specify the redaction optionsrepl_opt=ReplacementOptions(color)ex_red=ExactPhraseRedaction("John Doe",repl_opt)# Load the document to be redactedwithRedactor("./sample.docx")asredactor:# Apply the redactionresult=redactor.apply(ex_red)ifresult.status!=RedactionStatus.FAILED:# Save the redacted document, overwriting the original fileso=SaveOptions()so.add_suffix=Falseso.rasterize_to_pdf=Falseresult_path=redactor.save(so)print(f"Document redacted successfully.\nCheck output in {result_path}")else:print("Redaction failed!")if__name__=="__main__":save_overwriting_original_file()