Watermarks in PDFs can be removed by third-party tools. If you need watermarks that are very hard to remove, rasterize the document: convert its pages to images so the content — including the watermark — becomes non-editable. Access the PDF content tree with Watermarker.get_content() and call rasterize().
Warning
Rasterization is irreversible: the original text and vector content cannot be restored afterwards, and the output file size usually increases.
Rasterize the whole document
The example adds a watermark, rasterizes every page to a PNG image at 100 DPI, and saves the result.
fromgroupdocs.watermarkimportWatermarkerfromgroupdocs.watermark.watermarksimportTextWatermark,Font,Colorfromgroupdocs.watermark.options.pdfimportPdfLoadOptionsfromgroupdocs.watermark.contents.pdfimportPdfImageConversionFormatdefrasterize_document():withWatermarker("./document.pdf",PdfLoadOptions())aswatermarker:watermark=TextWatermark("CONFIDENTIAL",Font("Arial",19.0))watermark.foreground_color=Color.redwatermarker.add(watermark)# Rasterize every page at 100x100 DPI to PNG imagescontent=watermarker.get_content()content.rasterize(100,100,PdfImageConversionFormat.PNG)watermarker.save("./output.pdf")if__name__=="__main__":rasterize_document()
document.pdf is the sample file used in this example. Click here to download it.