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:
fromgroupdocs.redactionimportRedactor,RedactionStatusfromgroupdocs.redaction.options.drawingimportColor,Point,Sizefromgroupdocs.redaction.redactionsimport(PageAreaFilter,PageAreaRedaction,PageRangeFilter,PageSeekOrigin,RegionReplacementOptions,ReplacementOptions,)defuse_page_area_redaction():withRedactor("./multipage_sample.pdf")asredactor:# Text in the area: replacedtext_options=ReplacementOptions("[redacted]")text_options.filters=[PageRangeFilter(PageSeekOrigin.END,0,1),# the last pagePageAreaFilter(Point(306,0),Size(306,792)),# its right half]# Images in the area: covered with a boximage_options=RegionReplacementOptions(Color.chocolate,Size(100,100))result=redactor.apply(PageAreaRedaction("[a-z]+",text_options,image_options))ifresult.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.
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.
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.