Use advanced rasterization options

Use advanced rasterization options

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.

The following example demonstrates how to apply the AdvancedRasterizationOptions with default settings.

from groupdocs.redaction import Redactor
from groupdocs.redaction.options import SaveOptions, AdvancedRasterizationOptions
from groupdocs.redaction.redactions import ExactPhraseRedaction, ReplacementOptions


def use_advanced_rasterization_options():
    # Specify the redaction options
    repl_opt = ReplacementOptions("[personal]")
    ex_red = ExactPhraseRedaction("John Doe", repl_opt)

    # Load the document to be redacted
    with Redactor("./sample.docx") as redactor:

        # Apply the redaction
        redactor.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 = True
        so.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.

Binary file (PDF, 1.0 MB)

Download full output

Use grayscale rasterization option

The following example demonstrates how to apply the grayscale advanced rasterization option.

from groupdocs.redaction import Redactor
from groupdocs.redaction.options import SaveOptions, AdvancedRasterizationOptions


def use_grayscale_rasterization_option():
    # Load the document to be redacted
    with Redactor("./sample.docx") as redactor:

        # Save the document with the custom grayscale effect
        so = SaveOptions()
        so.rasterization.enabled = True
        so.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.

Binary file (PDF, 979 KB)

Download full output