Add text watermarks

To add a watermark to the HTML/JPG/PNG/PDF output, follow these steps:

  1. Create an instance of the HtmlViewOptions class (or PngViewOptions, or JpgViewOptions, or PdfViewOptions);
  2. Create a Watermark object and populate its properties;
  3. Call the watermark method of the HtmlViewOptions (or PngViewOptions, or JpgViewOptions, or PdfViewOptions) class and specify the object created on step 2;
  4. Call the Viewer.view() method.

The following code snippet shows how to apply the watermark to the output pages.

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import HtmlViewOptions, Watermark

def add_text_watermark():
    # Load document
    with Viewer("sample.docx") as viewer:
        # Create an HTML file for each document page.
        # {0} is replaced with the current page number in the file name.
        viewOptions = HtmlViewOptions.for_embedded_resources("add_text_watermark/output-watermark_{0}.html")
        # Add watermark.
        viewOptions.watermark = Watermark("This is a watermark")
        viewer.view(viewOptions)

if __name__ == "__main__":
    add_text_watermark()
sample.docx is the sample file used in this example. Click here to download it.
add_text_watermark/output-watermark_1.html (254 KB)
add_text_watermark/output-watermark_2.html (111 KB)
add_text_watermark/output-watermark_3.html (149 KB)
add_text_watermark/output-watermark_4.html (1003 KB)
add_text_watermark/output-watermark_5.html (88 KB)

Download full output