As an alternative to a local file, Redactor can open a document from stream.
The following example demonstrates how to load and redact a document using Stream:
fromgroupdocs.redactionimportRedactorfromgroupdocs.redaction.optionsimportRasterizationOptionsfromgroupdocs.redaction.redactionsimportDeleteAnnotationRedactiondefload_from_stream():# Specify the redaction options - remove all annotationsdel_red=DeleteAnnotationRedaction()# Load the document as a stream to be redactedwithopen("./sample.docx","rb")asstream_in:withRedactor(stream_in)asredactor:# Apply the redactionredactor.apply(del_red)# Save the redacted document to a stream as a rasterized PDFwithopen("./redacted-sample.pdf","wb")asstream_out:ro=RasterizationOptions()redactor.save(stream_out,ro)print("Document redacted successfully.")if__name__=="__main__":load_from_stream()
sample.docx is the sample file used in this example. Click here to download it.