Use PageAreaRedaction

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Redaction MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-redaction -- dnx GroupDocs.Redaction.Mcp --yes
Folders, licensing and more →

On this page

PageAreaRedaction redacts an area of chosen pages: the text that matches a regular expression, and the images and annotations, inside that area. Scope it with redaction filters on its text options: a PageRangeFilter for the pages and a PageAreaFilter for the area.

The following example redacts the right half of the last page of a PDF document:

from groupdocs.redaction import Redactor, RedactionStatus
from groupdocs.redaction.options.drawing import Color, Point, Size
from groupdocs.redaction.redactions import (
    PageAreaFilter,
    PageAreaRedaction,
    PageRangeFilter,
    PageSeekOrigin,
    RegionReplacementOptions,
    ReplacementOptions,
)


def use_page_area_redaction():
    with Redactor("./multipage_sample.pdf") as redactor:
        # Text in the area: replaced
        text_options = ReplacementOptions("[redacted]")
        text_options.filters = [
            PageRangeFilter(PageSeekOrigin.END, 0, 1),           # the last page
            PageAreaFilter(Point(306, 0), Size(306, 792)),       # its right half
        ]
        # Images in the area: covered with a box
        image_options = RegionReplacementOptions(Color.chocolate, Size(100, 100))

        result = redactor.apply(PageAreaRedaction("[a-z]+", text_options, image_options))
        if result.status != RedactionStatus.FAILED:
            result_path = redactor.save()
            print("Output saved to " + result_path)


if __name__ == "__main__":
    use_page_area_redaction()

multipage_sample.pdf is the sample file used in this example. Click here to download it.

Binary file (PDF, 3.5 MB)

Download full output

A page area is measured in points from the page’s top-left corner. Read a page’s size from redactor.get_document_info().pages, as the PDF redaction filters example does.

On this page