A “Hello, World!” example is often the first step when exploring GroupDocs.Redaction for Python via .NET. It serves as a simple test to confirm that your development environment is correctly set up and that the library is functioning as expected.
Overview
GroupDocs.Redaction for Python via .NET lets you search, redact, and remove sensitive information from various document formats. A wide range of supported formats makes it versatile for different use cases.
How to redact a document
The following steps demonstrate how to redact sensitive information from a document using GroupDocs.Redaction for Python via .NET:
Import the groupdocs.redaction classes you need.
Describe the redaction (here, an exact phrase to replace with a colored box).
Instantiate a Redactor with the path to the sample document.
Apply the redaction.
Save the result.
Complete example
The example below replaces every occurrence of the phrase “John Doe” with a semi-transparent red box and saves the redacted document:
fromgroupdocs.redactionimportRedactorfromgroupdocs.redaction.optionsimportSaveOptionsfromgroupdocs.redaction.redactionsimportExactPhraseRedaction,ReplacementOptionsfromgroupdocs.pydrawingimportColordefhello_world():# Draw a semi-transparent red box over every occurrence of "John Doe"options=ReplacementOptions(Color.from_argb(128,255,0,0))redaction=ExactPhraseRedaction("John Doe",options)# Load the document, apply the redaction, and save the resultwithRedactor("./sample.docx")asredactor:redactor.apply(redaction)save_options=SaveOptions()save_options.add_suffix=Truesave_options.rasterize_to_pdf=Truesave_options.redacted_file_suffix="redacted"result_path=redactor.save(save_options)print(f"Document redacted successfully. Output saved to {result_path}.")if__name__=="__main__":hello_world()
sample.docx is the sample file used in this example. Click here to download it.
This example rasterizes the result to a PDF named sample_redacted.pdf, so the redacted content cannot be recovered (save() rasterizes to PDF by default; the redacted_file_suffix option just controls the output name). To keep the original format instead, set rasterize_to_pdf = False.
Additional resources
This demo references the GroupDocs.Redaction for Python via .NET code samples.
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.