If you have a corporate sensitive data removal policy as a list of redaction rules, you don’t need to specify them in your code. You can specify an XML document with a list of pre-configured redactions.
Below is an example of redaction policy XML file (code properties mapping is obvious):
You can use RedactionPolicy.save() method to create XML documents of this structure, configuring redactions in runtime.
The following example demonstrates how to save a RedactionPolicy to an XML file.
Python
importgroupdocs.redactionasgrimportgroupdocs.redaction.optionsasgroimportgroupdocs.redaction.redactionsasgrrimportgroupdocs.pydrawingasgrddefrun():# Define color of redactioncolor=grd.Color.from_argb(255,220,20,60)# Configure Redactionsredactions=[grr.ExactPhraseRedaction("Redaction",grr.ReplacementOptions("[Product]")),grr.RegexRedaction("\\d{2}\\s*\\d{2}[^\\d]*\\d{6}",grr.ReplacementOptions(color)),grr.DeleteAnnotationRedaction(),grr.EraseMetadataRedaction(grr.MetadataFilters.ALL)]# Create policypolicy=gr.RedactionPolicy(redactions)# Save RedactionPolicypolicy.save("sample_policy.xml")
You can have as much policies, as you need, loading them to redact your documents.
An example below shows how to apply redaction policy to all files within given inbound folder, and save to one of outbound folders - for successfully updated files and for failed ones. Current date and time is used as a part of output file name:
Python
importgroupdocs.redactionasgrimportgroupdocs.redaction.optionsasgroimportgroupdocs.redaction.redactionsasgrrimportosfromos.pathimportjoindefrun():# Initialize RedactionPolicypolicy=gr.RedactionPolicy.load("sample_policy.xml")forfile_entryinos.listdir("\inbound_dir"):cur_file=os.path.join("\inbound_dir",file_entry)# Load the document to be redactedwithgr.Redactor(cur_file)asredactor:# Apply the redactionresult=redactor.apply(policy)# Get output folderresult_dir="\out_bound_done_dir"if(result.status==gr.RedactionStatus.FAILED):result_dir="\out_bound_failed_dir"output_file=join(result_dir,os.path.basename(cur_file))# Save filero=gro.RasterizationOptions()ro.enabled=Falsewithopen(output_file,"wb")asstream_out:redactor.save(stream_out,ro)
More resources
GitHub examples
You may easily run the code above and see the feature in action in our GitHub examples:
Along with full featured .NET library we provide simple, but powerful free Apps.
You are welcome to perform redactions for various document formats like PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Redaction App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.