You can search a document for existing watermarks and remove them. The example below finds a “CONFIDENTIAL” text watermark and removes it, producing a clean document.
Remove text watermarks
Iterate the search results in reverse so removing an item does not shift the indexes still to visit, and call remove() for each match.
fromgroupdocs.watermarkimportWatermarkerfromgroupdocs.watermark.search.search_criteriaimportTextSearchCriteriadefclear_watermark():withWatermarker("./watermarked-document.pdf")aswatermarker:possible=watermarker.search(TextSearchCriteria("CONFIDENTIAL"))# Remove in reverse so indexes stay valid as items are deletedforiinrange(len(possible)-1,-1,-1):watermarker.remove(possible[i])watermarker.save("./output.pdf")if__name__=="__main__":clear_watermark()
watermarked-document.pdf is the sample file used in this example. Click here to download it.
Use case: Remove outdated labels such as “Draft” or “Internal Use Only” before sharing a document externally.
Remove image watermarks
Image watermarks can be found with perceptual hashing and removed the same way:
fromgroupdocs.watermarkimportWatermarkerfromgroupdocs.watermark.search.search_criteriaimportImageDctHashSearchCriteriadefclear_image_watermark():withWatermarker("./watermarked-document.docx")aswatermarker:criteria=ImageDctHashSearchCriteria("./logo.png")criteria.max_difference=0.9possible=watermarker.search(criteria)# Remove in reverse so indexes stay valid as items are deletedforiinrange(len(possible)-1,-1,-1):watermarker.remove(possible[i])watermarker.save("./output.docx")if__name__=="__main__":clear_image_watermark()