You might need to save a document to any custom file at any location on the local disc or a even a Stream.
The following example demonstrates how to save a document to any location.
fromgroupdocs.redactionimportRedactor,RedactionStatusfromgroupdocs.redaction.optionsimportRasterizationOptionsfromgroupdocs.redaction.redactionsimportExactPhraseRedaction,ReplacementOptionsfromgroupdocs.pydrawingimportColordefsave_to_stream():# 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 document to a stream and convert its pages to imagesro=RasterizationOptions()ro.enabled=Truewithopen("./redacted-sample.pdf","wb")asstream_out:redactor.save(stream_out,ro)print("Document redacted successfully.\nCheck output in ./redacted-sample.pdf")else:print("Redaction failed!")if__name__=="__main__":save_to_stream()
sample.docx is the sample file used in this example. Click here to download it.