One of the main features of GroupDocs.Watermark is adding text watermarks to documents. You can add watermarks to documents or images from a local path, as well as from a stream. For a full list of supported formats, check Supported document formats.
Add a text watermark
To add a text watermark, follow these steps:
Open the document by passing its path (or a stream) to the Watermarker class, using a with block so the document is released automatically.
Style the watermark — for example, set foreground_color and alignment.
Call add() to apply the watermark and save() to write the result.
fromgroupdocs.watermarkimportWatermarkerfromgroupdocs.watermark.watermarksimportTextWatermark,Font,Colorfromgroupdocs.watermark.commonimportHorizontalAlignment,VerticalAlignmentdefadd_text_watermark():withWatermarker("./sample.pdf")aswatermarker:# Build the text watermark and style itwatermark=TextWatermark("Top Secret",Font("Arial",36.0))watermark.foreground_color=Color.redwatermark.horizontal_alignment=HorizontalAlignment.CENTERwatermark.vertical_alignment=VerticalAlignment.CENTERwatermark.rotate_angle=45.0watermark.opacity=0.4watermarker.add(watermark)watermarker.save("./output.pdf")if__name__=="__main__":add_text_watermark()
sample.pdf is the sample file used in this example. Click here to download it.
Run the program. A new watermarked document appears at the specified path.
What’s next
GroupDocs.Watermark offers many more capabilities for text watermarks — background and foreground colors, custom fonts, opacity, rotation, tiling, and absolute or relative positioning. See Adding text watermarks in the advanced guide.
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.