In order to use the advanced rasterization options you have to pass one of the options to Save method. In this case the document will be rasterized to PDF, but the scan-like effects will be applied to its pages.
fromgroupdocs.redactionimportRedactorfromgroupdocs.redaction.optionsimportSaveOptions,AdvancedRasterizationOptionsfromgroupdocs.redaction.redactionsimportExactPhraseRedaction,ReplacementOptionsdefuse_advanced_rasterization_options():# Specify the redaction optionsrepl_opt=ReplacementOptions("[personal]")ex_red=ExactPhraseRedaction("John Doe",repl_opt)# Load the document to be redactedwithRedactor("./sample.docx")asredactor:# Apply the redactionredactor.apply(ex_red)# Save the document with advanced options (convert pages into images, and save PDF with scan-like pages)so=SaveOptions()so.rasterization.enabled=Trueso.redacted_file_suffix="_scan"so.rasterization.add_advanced_option(AdvancedRasterizationOptions.BORDER)so.rasterization.add_advanced_option(AdvancedRasterizationOptions.NOISE)so.rasterization.add_advanced_option(AdvancedRasterizationOptions.GRAYSCALE)so.rasterization.add_advanced_option(AdvancedRasterizationOptions.TILT)result_path=redactor.save(so)print(f"Document redacted successfully.\nCheck output in {result_path}")if__name__=="__main__":use_advanced_rasterization_options()
sample.docx is the sample file used in this example. Click here to download it.
The following example demonstrates how to apply the grayscale advanced rasterization option.
fromgroupdocs.redactionimportRedactorfromgroupdocs.redaction.optionsimportSaveOptions,AdvancedRasterizationOptionsdefuse_grayscale_rasterization_option():# Load the document to be redactedwithRedactor("./sample.docx")asredactor:# Save the document with the custom grayscale effectso=SaveOptions()so.rasterization.enabled=Trueso.redacted_file_suffix="_scan"so.rasterization.add_advanced_option(AdvancedRasterizationOptions.GRAYSCALE)result_path=redactor.save(so)print(f"Document redacted successfully.\nCheck output in {result_path}")if__name__=="__main__":use_grayscale_rasterization_option()
sample.docx is the sample file used in this example. Click here to download it.