set_text method

set_text(text)

Adds Text watermark into the document.

def set_text(self, text: str):
    ...
ParameterTypeDescription
textstrText that is displayed as a watermark.

Remarks

The text length must be in the range from 1 to 200 inclusive. The text cannot be None or contain only whitespaces.

Exceptions

exceptioncondition
RuntimeError (Proxy error(ArgumentOutOfRangeException))Throws when the text length is out of range or the text contains only whitespaces.
RuntimeError (Proxy error(ArgumentNullException))Throws when the text is None.

set_text(text, options)

Adds Text watermark into the document.

def set_text(self, text: str, options: aspose.words.TextWatermarkOptions):
    ...
ParameterTypeDescription
textstrText that is displayed as a watermark.
optionsTextWatermarkOptionsDefines additional options for the text watermark.

Remarks

The text length must be in the range from 1 to 200 inclusive. The text cannot be None or contain only whitespaces.

If TextWatermarkOptions is None, the watermark will be set with default options.

Exceptions

exceptioncondition
RuntimeError (Proxy error(ArgumentOutOfRangeException))Throws when the text length is out of range or the text contain only whitespaces.
RuntimeError (Proxy error(ArgumentNullException))Throws when the text is None.

Examples

Shows how to create a text watermark.

doc = aw.Document()
# Add a plain text watermark.
doc.watermark.set_text(text='Aspose Watermark')
# If we wish to edit the text formatting using it as a watermark,
# we can do so by passing a TextWatermarkOptions object when creating the watermark.
text_watermark_options = aw.TextWatermarkOptions()
text_watermark_options.font_family = 'Arial'
text_watermark_options.font_size = 36
text_watermark_options.color = aspose.pydrawing.Color.black
text_watermark_options.layout = aw.WatermarkLayout.DIAGONAL
text_watermark_options.is_semitrasparent = False
doc.watermark.set_text(text='Aspose Watermark', options=text_watermark_options)
doc.save(file_name=ARTIFACTS_DIR + 'Document.TextWatermark.docx')
# We can remove a watermark from a document like this.
if doc.watermark.type == aw.WatermarkType.TEXT:
    doc.watermark.remove()

See Also